因为在已作的程序中出现“access violation at address 00000000”错误:访问了无效的地址,并只能查到前二条记录,第三条的记录即为空了,第四条时即显示数据库关闭,为此以以上的代码单独作一窗休中,也出现了"connot perform this operation on a closed dataset",一步步查之后,问题点在next代码上,但是对于数据库有showmessage函数查,却显示只能查到前二条记录,第三条的记录即为空了,第四条时即显示数据库关闭(我有10条记录在里面);但是确认数据库连接是没有问题的,原代码如下:
procedure tform1.addclass(ald:integer;fathernode:ttreenode);
var
mynode:ttreenode;
begin
with adoquery1 do
begin
close;
sql.Clear;
sql.Add('select * from tb1');
sql.Add('where fatherid='+inttostr(ald));
open;
showmessage(fieldbyname('cname').asstring);
while not eof do
begin
mynode:=treeview1.Items.AddChild(fathernode,fieldbyname('cname').AsString);
addclass(fieldbyname('autoid').AsInteger,mynode);
next;
end;
free;
end;
end;
procedure TForm1.FormShow(Sender: TObject);
begin
self.addclass(0,nil);
end;
end.
以上请大家帮一帮手,三天了,我都没有办法找到解决的办法,不知调那里才行;急啊
access:字段有三个:autoid(自动编号);cname(文本);fatherid(数字)

解决方案 »

  1.   

    free;你拿里不同用free,这样你把整个组件释放了,你前面有没有创建的代码,你这里是错误哦的!access violation at address 00000000”
    这里就是错误信息标记
      

  2.   

    procedure tform1.addclass(ald:integer;fathernode:ttreenode);
    var
      mynode:ttreenode;
      adoQr:TAdoQuery;
    begin
    try
    AdoQr:=TAdoQuery.Create(nil);
    with adoQr do
    begin
      close;
      Connection:=AdoConnection1;
      sql.Clear;
      sql.Add('select * from tb1');
      sql.Add('where fatherid='+inttostr(ald));
      open;
     // showmessage(fieldbyname('cname').asstring);
      while not eof do
      begin
        mynode:=treeview1.Items.AddChild(fathernode,fieldbyname('cname').AsString);
        addclass(fieldbyname('autoid').AsInteger,mynode);
        next;
      end;
      //free;
    end;
    finally
      AdoQr.Free;
    end;
    end;
      

  3.   

    估计是递归调用引起的AdoQuery1数据记录变化和混乱的原因。
      

  4.   

    while not eof do
    begin
    mynode:=treeview1.Items.AddChild(fathernode,fieldbyname('cname').AsString);
    addclass(fieldbyname('autoid').AsInteger,mynode);
    next;
    end;
    free; //这里的问题
    end;递归调用有问题,
      

  5.   

    哦,不错,是free的问题,但是现在虽然不报错了,但是还是只能取到二个记录,剩下的记录还是取不到;
      

  6.   

    你show adoquery1.recordcount 看看记录数多少?
      

  7.   

    竟找不到recordcount值,只有recordset属性才有