给你一段,你看看,我在写的,希望对你有帮助!
procedure ThwglForm.FormShow(Sender: TObject);
type
ttreedata=^ptreedata;
ptreedata=record
id:string;//厂家编号
cjname:string;//厂家名称
end;
var
treedata:ttreedata;
treenode1,treenode2:ttreenode;
id,cjname,pz:string;
begin
treeview1.Items.Clear ;
if utdatamoule.DataModule2.temphwglADODataSet.Active then
begin
utdatamoule.DataModule2.temphwglADODataSet.Close;
utdatamoule.DataModule2.temphwglADODataSet.CommandText :='select * from temphwgl' ;
utdatamoule.DataModule2.temphwglADODataSet.Open;
end
else
utdatamoule.DataModule2.temphwglADODataSet.Active :=true;
if utdatamoule.DataModule2.hwglcADODataSet.Active then
begin
utdatamoule.DataModule2.hwglcADODataSet.Close;
utdatamoule.DataModule2.hwglcADODataSet.CommandText :='select * from cj';
utdatamoule.DataModule2.hwglcADODataSet.Open;
end
else
utdatamoule.DataModule2.hwglcADODataSet.Active :=true;
if utdatamoule.DataModule2.hwglpzADODataSet.Active then
begin
utdatamoule.DataModule2.hwglpzADODataSet.Close;
utdatamoule.DataModule2.hwglpzADODataSet.CommandText :='select cjpz.cjbh, cjpz.pz from cjpz,cj where cj.cjbh=cjpz.cjbh';
utdatamoule.DataModule2.hwglpzADODataSet.Open;
end;
utdatamoule.DataModule2.hwglcADODataSet.Open;
utdatamoule.DataModule2.hwglcADODataSet.First;//到首条记录
while not utdatamoule.DataModule2.hwglcADODataSet.Eof do
begin
id:=utdatamoule.DataModule2.hwglcADODataSet.fieldbyname('cjbh').AsString ;
cjname:=utdatamoule.DataModule2.hwglcADODataSet.fieldbyname('cj').AsString ;
new(treedata);
treedata^.id :=id;
treedata^.cjname :=cjname;
treenode1:=treeview1.Items.Addchild(nil,cjname);
treenode1.Data :=treedata;
treenode1.StateIndex :=1;
utdatamoule.DataModule2.hwglpzADODataSet.Open;
utdatamoule.DataModule2.hwglpzADODataSet.First ;
while not utdatamoule.DataModule2.hwglpzADODataSet.Eof do
begin
if utdatamoule.DataModule2.hwglcADODataSet.fieldbyname('cjbh').asinteger=utdatamoule.DataModule2.hwglpzADODataSet.FieldByName('cjbh').AsInteger then
begin
id:=utdatamoule.DataModule2.hwglpzADODataSet.fieldbyname('cjbh').AsString ;
pz:=utdatamoule.DataModule2.hwglpzADODataSet.fieldbyname('pz').AsString ;
new(treedata);
treedata^.id :=id;
treedata^.cjname:=pz;
treenode2:=treeview1.Items.Addchild(treenode1,pz);
treenode2.Data :=treedata;
treenode2.StateIndex :=2;
end;
utdatamoule.DataModule2.hwglpzADODataSet.Next ;
end;
utdatamoule.DataModule2.hwglcADODataSet.Next ;
end;
panel2.Visible :=false;
panel3.Visible :=true;
end;