TO:catthunder,請幫忙~~~
unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Db, ADODB;
Type
  TItem = class
  private
   ChildItem:String;
  public
   ID:string;
   procedure AddChild(SChildItem:String);
end;
type
  TForm1 = class(TForm)
    ADOConnection1: TADOConnection;
    ADODataSet1: TADODataSet;
    ListBox1: TListBox;
    Edit1: TEdit;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
procedure ExpandBom(AParentBom:TItem);
var
  Form1: TForm1;implementation{$R *.DFM}
procedure TItem.AddChild(SChildItem:string);
begin
 Form1.ListBox1.Items.Add(SChildItem);
end;
procedure ExpandBom(AParentBom:TItem);
var
 TmpItem:TItem;
 SChildItem:String;
begin
try
 tmpItem:=TItem.Create;
 with Form1.ADODataSet1 do
 begin
  close;
  CommandText:='select * from ps_mstr where ps_par=:par';
  Parameters.paramByName('par').Value:=AParentBom.id;
  open;
  if Fields[0].IsNull then exit;
  while not eof do
  begin
  SChildItem:=FieldByName('ps_comp').asString;
  tmpItem.id:=SChildItem;
  AParentBom.AddChild(SChildItem);
  ExPandBom(tmpItem);
  next;
  end;
 end;
finally
tmpItem.Free;
end;
end;procedure TForm1.Button1Click(Sender: TObject);
var
tmp:TItem;
begin
tmp:=TItem.Create;
tmp.id:=edit1.text;
ExpandBom(tmp);
end;end.