我在form1中有:(ADOQueryfilelist : TADOQuery;)
……
 public
    procedure Dataconn1(SqlComm:String;OpenOrExe:Boolean) ;
……
{$R *.dfm}
……
 Procedure Tform1.Dataconn1(SqlComm:String;openOrExe:Boolean);
begin
 Try
  ADOQueryfilelist.Close;
  ADOQueryfilelist.SQL.Clear;
  ADOQueryfilelist.SQL.Add(SqlComm);
  if OpenOrExe=True then
     ADOQueryfilelist.Open
  else
     ADOQueryfilelist.ExecSQL; Except
  Application.MessageBox('数据库异常','数据库错误',MB_OK);
  
 end;
end;
……
我在form2中有:
……
type
  procedure BtnFindClick(Sender: TObject);
……
{$R *.dfm}
……
procedure Tform2.BtnFindClick(Sender: TObject);
var
findcount:integer;
findsql:string;
begin
  findsql:='select * from tablename where substring(fieldname,1,2)='01'';
  form1.Dataconn1(findsql,true);
  findcount:=form1.ADOQueryfilelist.RecordCount;//执行时老是在这句出错,为什么?
  Application.MessageBox('共找到findcount条记录','信息提示',MB_OK);//这里“findcount”这个变量可以这样夹在中间吗?
end;
……
end.//上述程序编译顺利通过,但是在执行时老是在 “findcount:=form1.ADOQueryfilelist.RecordCount;”一句出错。这是为什么?高手帮看一下,拜托了

解决方案 »

  1.   

    var b:boolean;
      
      findsql:='select * from tablename where substring(fieldname,1,2)='01'';
      b:=Assigned(Form1);
      if b then
        showmessage('ok');//看这句执行了么?
      form1.Dataconn1(findsql,true);
      findcount:=form1.ADOQueryfilelist.RecordCount;//执行时老是在这句出错,为什么?
      Application.MessageBox('共找到findcount条记录','信息提示',MB_OK);//这里
      

  2.   

    ADOQueryfilelist的CONNCTION属性赋值了吗?
    FORM1在FORM2中是否有实例被创建?
    //下面这句对吗?
    findsql:='select * from tablename where substring(fieldname,1,2)='01'';
    我认为应该是findsql:='select * from tablename where substring(fieldname,1,2)=''01''';
    //这句应该该成:
    var str:string;
    str:='共找到'+inttostr(findcount)+'条记录';
    Application.MessageBox(str,'信息提示',MB_OK);
      

  3.   

    1) findcount:=form1.ADOQueryfilelist.RecordCount;//执行时老是在这句出错,为什么?
    在前面加一个判断就没问题了。如下
      if Not Form1.ADOQueryfilelist.IsEmpty then
        FindCount := Form1.ADOQueryfilelist.RecordCount;
    2)findsql应该是下面的写法;
    findsql:='select * from tablename where substring(fieldname,1,2)=''01''';3)“findcount”这个变量可以这样夹在中间吗?
    不行 ,如下
    Application.MessageBox(PChar('共找到'+inttostr(findcount)+'条记录'),'信息提示',MB_OK);
      

  4.   

    我同意 xuejinlong(-@判官@-) 的观点,他说的对,你试试
      

  5.   

    xuejinlong maybe right!现在结果如何?期待答复