H
hurryman
Unregistered / Unconfirmed
GUEST, unregistred user!
利用树型结构与数据库结合的一段程序,让我头疼了一下午,大家看看,特别是这方面有经验的高手
我用ACCESS建了两个库
table1 table2
cjh -> pzh
cj | pz
pzh---- lb
jg
我用treeview来装入这两个数据库,代码如下:
procedure TForm1.Button1Click(Sender: TObject);
type
ttreedata=^ptreedata;
ptreedata=record
id:string;
name:string;
end;
var
treedata:ttreedata;
treenode1,treenode2:ttreenode;
id,name:string;
begin
utdatamoule.DataModule2.hwglcADODataSet.Open;
utdatamoule.DataModule2.hwglcADODataSet.First;
while not utdatamoule.DataModule2.hwglcADODataSet.Eof do
begin
id:=utdatamoule.DataModule2.hwglcADODataSet.fieldbyname('pzh').AsString ;
name:=utdatamoule.DataModule2.hwglcADODataSet.fieldbyname('cj').AsString ;
new(treedata);
treedata^.id :=id;
treedata^.name :=name;
treeview1.Items.Add(nil,name);
treenode1.Data :=treedata;
treenode1.StateIndex :=1;
utdatamoule.DataModule2.hwglpADODataSet.Open;
utdatamoule.DataModule2.hwglpADODataSet.First ;
while not utdatamoule.DataModule2.hwglpADODataSet.Eof do
begin
if utdatamoule.DataModule2.hwglpADODataSet.FieldByName('pzh').AsString=id then
begin
id:=utdatamoule.DataModule2.hwglpADODataSet.fieldbyname('pzh').AsString ;
name:=utdatamoule.DataModule2.hwglpADODataSet.fieldbyname('pz').AsString ;
new(treedata);
treedata^.id :=id;
treedata^.name :=name;
treenode2:=treeview1.Items.Addchild(treenode1,name);
treenode2.Data :=treedata;
treenode2.StateIndex :=2;
utdatamoule.DataModule2.hwglpADODataSet.Next ;
end
else
utdatamoule.DataModule2.hwglpADODataSet.Next ;
end;
utdatamoule.DataModule2.hwglcADODataSet.Next ;
end;
end;
运行提示出错:
project pjhwgl.exe raised exception class eaccessviolation with
message 'access violation at address 004552cf in module pjhwgl.exe'.
read of address 00000025
该如何解决呢
我用ACCESS建了两个库
table1 table2
cjh -> pzh
cj | pz
pzh---- lb
jg
我用treeview来装入这两个数据库,代码如下:
procedure TForm1.Button1Click(Sender: TObject);
type
ttreedata=^ptreedata;
ptreedata=record
id:string;
name:string;
end;
var
treedata:ttreedata;
treenode1,treenode2:ttreenode;
id,name:string;
begin
utdatamoule.DataModule2.hwglcADODataSet.Open;
utdatamoule.DataModule2.hwglcADODataSet.First;
while not utdatamoule.DataModule2.hwglcADODataSet.Eof do
begin
id:=utdatamoule.DataModule2.hwglcADODataSet.fieldbyname('pzh').AsString ;
name:=utdatamoule.DataModule2.hwglcADODataSet.fieldbyname('cj').AsString ;
new(treedata);
treedata^.id :=id;
treedata^.name :=name;
treeview1.Items.Add(nil,name);
treenode1.Data :=treedata;
treenode1.StateIndex :=1;
utdatamoule.DataModule2.hwglpADODataSet.Open;
utdatamoule.DataModule2.hwglpADODataSet.First ;
while not utdatamoule.DataModule2.hwglpADODataSet.Eof do
begin
if utdatamoule.DataModule2.hwglpADODataSet.FieldByName('pzh').AsString=id then
begin
id:=utdatamoule.DataModule2.hwglpADODataSet.fieldbyname('pzh').AsString ;
name:=utdatamoule.DataModule2.hwglpADODataSet.fieldbyname('pz').AsString ;
new(treedata);
treedata^.id :=id;
treedata^.name :=name;
treenode2:=treeview1.Items.Addchild(treenode1,name);
treenode2.Data :=treedata;
treenode2.StateIndex :=2;
utdatamoule.DataModule2.hwglpADODataSet.Next ;
end
else
utdatamoule.DataModule2.hwglpADODataSet.Next ;
end;
utdatamoule.DataModule2.hwglcADODataSet.Next ;
end;
end;
运行提示出错:
project pjhwgl.exe raised exception class eaccessviolation with
message 'access violation at address 004552cf in module pjhwgl.exe'.
read of address 00000025
该如何解决呢