数据结构如下 :
Crear tabla [tbtree] (
[Id] [varchar] (4) recopilar no nulo,
[Contexto] [nvarchar] (50) nulo,
[ParentId] [Varchar] (4) NULL,
Restricción [pk_tbtree] clave principal agrupada
(
[IDENTIFICACIÓN]
) En [primario]
) En [primario]
代码如下 :
lProcedure tForm1.Readtree (tnode: ttreeNode; fValue: string); lvar li: entero; l flist: tstringlist; l flist1: tstringlist; l str: cadena; lbegin l qrytree.close; l qrytree.sql.clear; l qrytree.sql.add ('seleccione ParentId, id, contexto de 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 Aunque no qrytree.eof do l begin l flist.add (trim (Qrytree.fieldByName ('context'). Astring)); l flist1.add (qrytree.fieldbyname ('id'). astring); l qrytree.next; prestar; l para i: = 0 a flist.count-1 do l begin ls: = flist1.strings [i]; l str: = flist.strings [i]; l snode: = treeView1.items.addchild (tnode, str); l Readtree (Snode, S); prestar; l flist.free; l flist1.free; prestar;