procedure 1; //第一层
var
i:integer;
node:ttreenode;
myrecord
myrec;
begin
tv1.Items.Clear;
qry_shi.close;
qry_shi.sql.clear;
qry_shi.sql.add('select * from table');
qry_shi.open;
qry_shi.First;
if qry_shi.recordcount<1 then
exit;
for i:=0 to qry_shi.recordcount-1 do
begin
New(MyRecord);
myrecord^.code:=qry_shi.fields[0].asstring;//存储数据库的索引字段,将来可以读取
shicode:=trim(qry_shi.fields[0].asstring);
node:=tv1.Items.AddObject (nil,shicode+'-'+
qry_shi.fields[1].asstring,myrecord);
second(node,shicode);//第二层
node.ImageIndex:=1;
qry_shi.Next;
end;
end;
procedure tform1.second;
var
i:integer;
node1:ttreenode;
tuancode:string;
myrecord
myrec;
begin
qry_tuan.close;
qry_tuan.sql.clear;
qry_tuan.sql.add('select * from table2');
qry_tuan.open;
qry_tuan.First;
if qry_tuan.recordcount<1 then
exit;
for i:=0 to qry_tuan.recordcount-1 do
begin
new(myrecord);
tuancode:=qry_tuan.fields[1].asstring;
myrecord^.code:=qry_tuan.fields[1].asstring;
node1:=tv1.Items.AddChildObject (node,trim(copy(tuancode,4,3))+'-'
+qry_tuan.fields[2].asstring,myrecord);
third(node1,shicode,tuancode);
node1.ImageIndex:=1;//设node上的动态image,得与imagelist配合
qry_tuan.Next;
end;
end;