{绘制树:
QryObj:查询控件名称;MyTreeView:树型控件名;SQL:查询语句;
Field:主字段;Index:图片索引
}
procedure DrawTree(ChildQryObj,GrandsonQryObj:TADOQuery;MyTreeView:TTreeView;LayerNum,MainIndex,ChildIndex,GrandsonIndex:Integer;ChildSQL,GrandsonSQL,ChildField,ChildGrandsonField,GrandsonField:string);
var
MainNode,ChildNode,GrandsonNode,lnNode:TTreeNode;
begin
with MyTreeView.Items do
begin
Clear;
MainNode:=add(nil,'信息名称列表');
MainNode.ImageIndex:=MainIndex;
MainNode.SelectedIndex:=MainIndex;
DateSelect(ChildQryObj,ChildSQL);
while not ChildQryObj.Eof do
begin
ChildNode:= AddChild(MainNode,ChildQryObj.fieldbyname(''+ChildField+'').AsString);
ChildNode.ImageIndex:=ChildIndex;
ChildNode.SelectedIndex :=ChildIndex;
if LayerNum>2 then
begin
DateSelect(GrandsonQryObj,GrandsonSQL+''''+ChildNode.Text+'''');
while not GrandsonQryObj.Eof do
begin
GrandsonNode:=AddChild(ChildNode,GrandsonQryObj.fieldbyname(''+GrandsonField+'').AsString );
GrandsonNode.ImageIndex :=GrandsonIndex;
GrandsonNode.SelectedIndex :=GrandsonIndex;
GrandsonQryObj.Next;
end;
lnNode := GetFirstNode;
while not (lnNode = nil) do
begin
lnNode.Expand(true);
lnNode := lnNode.GetNextSibling;
end;
end;
ChildQryObj.Next;
end;
end;
end;