The data structure is as follows: 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] The code is as follows:
l
Procedure TFORM1.Readtree (TNode: Ttreenode; Fvalue: String);
l
VAR
l
i: integer;
l
Flist: tstringlist;
l
FLIST1: TSTRINGLIST;
l
Str: string;
l
Begin
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 (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;
l
END;