my codes as follows
procedure TMainForm.AddRec(catalog,text:string);
var
childnode,rootnode,tempnode:TTreeNode;
i,childcount:integer;
begin
rootnode:=TreeView1.Items[0];
i:=0;
childcount:=rootnode.count;
while (i<childcount)
and (catalog<>rootnode.item.Text) do
inc(i);
if i=childcount then
childnode:=TreeView1.Items.AddChild(rootnode,catalog)
else
childnode:=rootnode.Item;
childnode.ImageIndex:=1;
childnode.SelectedIndex:=2;
tempnode:=TreeView1.Items.AddChild(childnode,text);
tempnode.ImageIndex:=3;
tempnode.SelectedIndex:=3;
TreeView1.Selected:=tempNode;
end;
procedure TMainForm.updateTreeView;
begin
TreeView1.Items.Clear;
TreeView1.Items.AddChild(nil,'笔记');
// rootnode:=TreeView1.Items.
with Data.ClientDataSet1 do
begin
if not active then open;
first;
while not eof do
begin
AddRec(FieldbyName('catalog').asstring,FieldbyName('title').asstring);
next;
end;
end;
end;