数据结构:id varchar 18 not null primary key ,
upid varchar 18 not null default 0,
name varchar 20 not null unique,
desc varchar 80 ,
level smallint not null default 0 (例100 => 1 , 100100 => 2 )
function TDMPUB.treeAdd(var Atree :TTreeView) :boolean;
var node :array of TTreenode;
rootnode : TTreenode;
str0,str :string;
Alevel :integer;
begin
str0 := 'select max(level)'
+ ' from epgroup ';
str := 'select level,groupid,groupupid,groupname,groupdesc'
+ ' from epgroup order by groupid';
with qrypub do begin
close;
sql.Clear;
sql.Add(str0);
open;
if fields[0].AsInteger > 0 then
setlength(node,fields[0].AsInteger+1)
else
exit;
node[0] := Atree.Items.GetFirstNode;
close;
sql.Clear;
sql.Add(str);
open;
while not eof do begin
alevel := fieldbyname('level').asinteger;
node[alevel] := atree.Items.AddChild(node[alevel-1],
fieldbyname('groupid').AsString+'_'+ fieldbyname('groupname').AsString );
next;
end;
result := true;
end;
end;
另:加data指针会更好控制,谁有这部分就代码贴出来吧