dll:
procedure ConnRS(ConnStr,SqlStr:string);
var
  ADO:TADOQuery;
begin
  ADO.ConnectionString:=ConnStr;
  ADO.Close;
  ADO.SQL.Clear;
  ADO.SQL.Add(SqlStr);
  ADO.Open;
end;exports
  ConnRs;窗体:
procedure ConnRs(ConnStr,SqlStr:string); stdcall;
external 'ConnRs.DLL';procedure TForm1.Button1Click(Sender: TObject);
begin
  ConnRs('Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db.mdb;Persist Security Info=False','select * from users');
end;

解决方案 »

  1.   

    这是字符串内存管理出错了,是由于borland的字符串格式跟操作系统标准字符串格式不一致造成的。你在引用DLL的工程文件(.dpr)里面的uses后面加上Sharemem, 如果程序要打包还要把Delphi目录的Borlndmm.dll一起打包
      

  2.   

    回 outer2000(天外流星) :
    还有什么问题啊,帮我看看啊回 hthunter(核桃) :
    加了Sharemem还是不行
      

  3.   

    hthunter(核桃)的方法好像见过,不记得能不能行了,你也可改用PChar来传递参数。
    另外dll中的函数声明也该加stdcall吧
      

  4.   

    library Project1;{ Important note about DLL memory management: ShareMem must be the
      first unit in your library's USES clause AND your project's (select
      Project-View Source) USES clause if your DLL exports any procedures or
      functions that pass strings as parameters or function results. This
      applies to all strings passed to and from your DLL--even those that
      are nested in records and classes. ShareMem is the interface unit to
      the BORLNDMM.DLL shared memory manager, which must be deployed along
      with your DLL. To avoid using BORLNDMM.DLL, pass string information
      using PChar or ShortString parameters. }uses
      SysUtils,ADODB,ACTIVeX,
      Classes;{$R *.res}
    procedure ConnRS(ConnStr,SqlStr:PCHAR);export;
    var
      ADO:TADOQuery;
    begin
      activex.CoInitialize(nil);
      ADO:=TADOQUERY.Create(NIL);
      ADO.ConnectionString:=ConnStr;
      ADO.Close;
      ADO.SQL.Clear;
      ADO.SQL.Add(SqlStr);
      TRY
        ADO.Open; //如果执行不是返回DATASET的,用EXCUTESQL方法
      FINALLY
        ADO.Free ;
        activex.CoUninitialize ;
      END;
    end;exports
      ConnRs name 'ConnRs';
    begin
    end.
      

  5.   

    http://www.yesky.com/20011031/202937.shtml