一个树的递归搜索

procedure TForm1.GetID(ID:Integer;var ResultList:TStringList);
var
  qry:TADOQuery;
begin
   //
   qry:=TADOQuery.Create(self);
   try
     with qry do
     begin
       Connection:=ADOConnection1;
       sql.Text:='Select * from ERP_PUB_BASE where ParID='+IntToStr(ID);
       open;
       if Recordcount=0 then exit;
       while not Eof do
       begin
         ResultList.Add(FieldByName('infoname').AsString);
         next;
       end;
       First;
       while not Eof do
       begin
          GetID(fieldbyname('ID').AsInteger,ResultList);
          next;
       end;
     end;
     finally
       qry.Free;
     end;

end;

这样搜索一棵树的子级及叶。

posted on 2005-02-28 18:03  qufo  阅读(333)  评论(0编辑  收藏  举报

导航