procedure TForm1.FormShow(Sender: TObject);
var i,j:integer;
node1,node2:array of  TTreeNode;
s1,s2:string;
begin
with table1 do
 begin
  close;
  commandtype:=cmdtext;
  commandtext:='select xmmc,cwxmdm from public_cwxmfl';
  open;
  setlength(node1,RecordCount);
  end;
  for i:=0 to table1.RecordCount-1 do
   begin
    tv1.Items.Clear ;
    node1[i]:=tTreeNode.Create(tv1.Items );
    s1:=table1.Fields[i].AsString ;
    tv1.Items.AddFirst(node1[i],s1 );
    //
    with table2 do
     begin
      close;
      commandtype:=cmdtext;
      commandtext:='select * from public_hjxmfl where cwxmdm='
                  +#39+table1.Fieldbyname('cwxmdm').AsString +#39;
      open;
      setlength(node2,table2.RecordCount );
     end;
    for j:=0 to table2.RecordCount-1 do
     begin
      tv1.Items.Clear ;
      node1[j]:=tTreeNode.Create(tv1.Items );
      s2:=table2.Fields[j].AsString ;
      tv1.Items.AddFirst(node1[j],s2 );
     end;
   end;
  table1.Next ;
 end;

解决方案 »

  1.   

    2个数据集是 ADOSETDATA  MSSQL2000  谢谢各位啦
      

  2.   

    程序设计思路有问题
    1、Node是不需要自已创建的
    2、在内层循环里tv1.Items.Clear ,结果什么都没了,以上的做了也白做
    3、Node1的length是tabel1的RecordCount,可是内循坏中的j是以Table2的RecordCount作边界的,二者不同就不能用node1[j]了,这也是为什么会出数组下标越界的原因
      

  3.   

    内循环应该是node2 真是粗心:)
    但是越界是在两次循环后?为什么
      

  4.   

    那就要看你的Table2的记录有多少了