Delphi动态创建树
今天天气好晴朗处处好风光,好天气好开始,图老师又来和大家分享啦。下面给大家推荐Delphi动态创建树,希望大家看完后也有个好心情,快快行动吧!
CREATE TABLE [tbTree] (
[ID] [varchar] (4) COLLATE NOT NULL ,
[Context] [nvarchar] (50) NULL ,
[ParentID] [varchar] (4) NULL ,
CONSTRAINT [PK_tbTree] PRIMARY KEY CLUSTERED
(
[ID]
) ON [PRIMARY]
) ON [PRIMARY]
代码如下:
lprocedure TForm1.ReadTree(tnode:TTreeNode;Fvalue: String); lVar l i: integer; l Flist:TStringList; l Flist1:TStringList; l str:string; lbegin l qryTree.close; l qryTree.sql.clear; l qryTree.sql.add('select Parentid,id,context from tbtree'); l qryTree.sql.add('where isnull(Parentid,'''')='); l qryTree.sql.add(''''+Fvalue+''''); l qryTree.Open; l qryTree.First; l Flist:=TStringList.Create; l Flist1:=TStringList.Create; l while not qryTree.eof do l begin l Flist.Add(trim(qryTree.fieldbyname('context').asstring)); l Flist1.Add(qryTree.fieldbyname('id').asstring); l qryTree.next; l end; l for i:= 0 to flist.Count-1 do l begin l s:=flist1.Strings[i]; l str:=flist.Strings[i]; l snode:=Treeview1.items.addchild(tnode,str); l ReadTree(snode,s); l end; l flist.free; l flist1.free; lend;