procedure TForm1.CreateTree;
procedure CreateTree(Pre:string;preNode:TTreeNode);
var
pInfo
TNodeInfo;
node:TTreeNode;
sql:string;
Query:TADOQUery;
begin
Query:=TADOQuery.Create(nil);
Query.ConnectionString:='Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=PeaqeNet9001;Data Source=.';
sql:= Format('Select * from V_Domain where UPId=%s', [QuotedStr(pre)]);
Query.Close;
Query.SQL.Clear;
Query.SQL.Add(sql);
Query.Open;
Query.First;
while not Query.Eofdo
begin
new(pInfo);
pInfo.preId:=Query.Fields[0].AsString;
pInfo.id:=Query.Fields[4].AsString;
If (pInfo.id=pInfo.preId)then
begin
node:=tree.Items.AddChild(preNode,pInfo.id);
node.Data:=pInfo;
node.OverlayIndex:=2;
Query.Next;
//CreateTree(pInfo.id,node);
// Query.Next;
end
else
//If pInfo.id<> pInfo.preId then
begin
node:=tree.Items.AddChild(preNode,pInfo.id);
node.Data:=pInfo;
node.ImageIndex:=1;
Node.SelectedIndex:=2;
//node.OverlayIndex:=2;
//node.StateIndex:=1;
CreateTree(pInfo.id,node);
Query.Next;
end;
//Query.Next;
end;
Query.Close;
Query.Free;
end;
begin
createTree('1',nil);
tree.FullExpand;
end;