Delphi动态创建树
2006-02-04 13:51:25 来源:WEB开发网核心提示:数据结构如下: CREATE TABLE [tbTree] ( [ID] [varchar] (4) COLLATE NOT NULL , [Context] [nvarchar] (50) NULL , [ParentID] [varchar] (4) NULL , CONSTRAINT [PK_tbTree]
数据结构如下:
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;
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;
[]
- ››Delphi之多线程实例
- ››Delphi SelectSingleNode的使用 根据节点属性获取...
- ››Delphi接口详述
- ››delphi 远程调试
- ››Delphi与DirectX之DelphiX(34): TDIB.Lightness()...
- ››Delphi Application.MessageBox详解
- ››Delphi只能运行一个程序实例的两种方法
- ››动态调用对象事件
- ››创建基于PPTP的站点到站点VPN连接:ISA2006系列之...
- ››创建基于L2TP的站点到站点的VPN连接:ISA2006系列...
- ››创建一个Twisted Reactor TCP服务器
- ››动态创建控件支持事件响应并可保存与读取
更多精彩
赞助商链接