我没见过DBTree是什么样的,不过我有一段程序是我以前写的,你可以看看:
//从数据库向TreeView中加入树形结构
procedure loadtree(tree:Ttreeview;DBname:string);
var
loaded_number:integer;//已装入记录数
level:integer;//记录当前正在装入的节点的级别
loaded_item:Ttreenode;
i:integer;
begin
tree.setfocus;//设定焦点
tree.items.clear;
//初始化表
datamoduleall.Table_archives_tree.Active:=false;
datamoduleall.Table_archives_tree.tablename:=Dbname;
datamoduleall.Table_archives_tree.active:=true;
additemtotree(datamoduleall.table_archives_tree,tree,0,nil,-1);
end;
procedure additemtotree(tabletree:Ttable;tree:Ttreeview;
level:integer;Node: TTreeNode;code:integer);//用递归算法
var
itemcode:integer;
tempnode:ttreenode;
begin
tabletree.Filtered:=false;
tabletree.Filter:='itemlevel='+inttostr(level);
tabletree.Filtered:=true;
if tabletree.RecordCount<=0 then exit;
tabletree.first;
while not tabletree.EOF do
begin
if level=0 then
begin
itemcode:=tabletree.fieldbyname('itemcode').asinteger;
if (tabletree.fieldbyname('itemparent').asinteger=code) then
begin
tempnode:=tree.items.add(nil,tabletree.fieldbyname('itemname').asstring);
tempnode.data:=addcode(itemcode);
additemtotree(tabletree,tree,level+1,tempnode,itemcode);
end;
end
else
begin
itemcode:=tabletree.fieldbyname('itemcode').asinteger;
if (tabletree.fieldbyname('itemparent').asinteger=code) then
begin
tempnode:=tree.items.addchild(node,tabletree.fieldbyname('itemname').asstring);
tempnode.data:=addcode(itemcode);
additemtotree(tabletree,tree,level+1,tempnode,itemcode);
end;
end;
tabletree.Filtered:=false;
tabletree.Filter:='itemlevel='+inttostr(level);
tabletree.Filtered:=true;
tabletree.Locate('itemcode',itemcode,[loCaseInsensitive]);
tabletree.next;
end;
end;
表结构如下:(paradox)
itemcode 自动增量型 关键词
itemparent 整型 父结点
itemlevel 整型 节点层次
itemname 字符型 节点名
ItemExplain 备注型 节点说明