Procedure AutoSeleCustInfo(Var cSelField1 : String);
Var CustADO : TADODataSet;
Begin
  With CustADO Do Begin
      Create(Nil);
      Connection := DM.Conection1 ;
      Close;
      CommandText := 'Select cCusPPerson,cCusDepart From Customer Where cCusCode = '''
      + cSelField1 + '''';
      Open ;
      If RecordCount <> 0 Then Begin
        First;
        DM.SubstituteDispatchList.FieldByName('cDepCode').AsString := FieldByName('cCusDepart').AsString ;
        DM.SubstituteDispatchList.FieldByName('cPersonCode').AsString := FieldByName('cCusPPerson').AsString ;
      End;
      Close;
      Destroy ;
  End;
End;引用这个过程时,执行到Connection := DM.Conection1 ;这一句时出现内存错误,请大侠指点。

解决方案 »

  1.   

    将Create(Nil);去掉,在with语句前面加上CustADO := TADODataSet.Create(self);
      

  2.   

    [Error] PubToolsDB.pas(67): Undeclared identifier: 'Self'
      

  3.   

    按cuteant的意见更改后无法编译,出现:[Error] PubToolsDB.pas(67): Undeclared identifier: 'Self'
      

  4.   

    哦,不好意思,写错了CustADO := TADODataSet.Create;
      

  5.   

    cuteant,这两种方法本质区别在哪里呢?为什么我的方法就出错呢?我原来的写法在其他的地方又可以,我不太理解。
      

  6.   

    本质区别就是,你既然写出来with CustADO do,表明CustADO已经存在了但事实上你这个时候根本还没有Create
      

  7.   

    提示:[Error] PubToolsDB.pas(67): Not enough actual parameters
    改成这样就对了:CustADO := TADODataSet.Create(Nil);
    大侠cuteant,能否指教这两种方法的区别呢?
      

  8.   

    区别?关键是看Create函数有没有带参数而已
      

  9.   

    我发现了,我原来的方法不出错是因为:创建在先,然后在函数里用With语句打开和使用,所以不出错。