你看这样可以吗?
var
root,r1,r2,r3,rtemp: TTreeNode;
begin
Form7.TreeView1.Items.Clear;
root := Form7.TreeView1.Items.Add(nil,'用户管理');
root.ImageIndex := 1;
root.SelectedIndex := 1;
r1 := Form7.TreeView1.Items.AddChild(root,'t1);
r2 := Form7.TreeView1.Items.AddChild(root,'t2');
r3 := Form7.TreeView1.Items.AddChild(root,'t3);
r1.ImageIndex := 2;
r2.ImageIndex := 2;
r3.ImageIndex := 2;
r1.SelectedIndex := 4;
r2.SelectedIndex := 4;
r3.SelectedIndex := 4;
Form1.Query1.Active := false;
Form1.Query1.Close;
Form1.Query1.SQL.Clear;
Form1.Query1.SQL.Add('Select * from login.dbf as login');
Form1.Query1.ExecSQL;
Form1.Query1.Active := true;
Form1.Query1.First;
while not Form1.Query1.Eof do
begin
if Form1.Query1.Fields[2].AsInteger=1 then
begin
rtemp := Form7.TreeView1.Items.AddChild(r1,Form1.Query1.Fields[0].AsString);
end;
if Form1.Query1.Fields[2].AsInteger=2 then
begin
rtemp := Form7.TreeView1.Items.AddChild(r2,Form1.Query1.Fields[0].AsString);
end;
if Form1.Query1.Fields[2].AsInteger=3 then
begin
rtemp := Form7.TreeView1.Items.AddChild(r3,Form1.Query1.Fields[0].AsString);
end;
rtemp.ImageIndex := 3;
Form1.Query1.Next;
end;
end;