如题

解决方案 »

  1.   

    dll输出的函数,加一个参数类型,就用TADOConnection* ado;然后,外面的exe调用dll中,把ado作为参数传递进去就OK了
      

  2.   

    you should not pass the connection if you have many users. The connection should be closed as soon as possible. pass the connect string is OK.
      

  3.   

    在dll里显示窗体的函数的参数中加入Tadoconnection参数
    如:
    dll:
    procedure f_showform(p_cnt: TADOConnection;p_handle: HWND);stdcall;
    var
      v_frm: TForm1;
    begin
      Application.Handle := p_handle;
      if not p_cnt.Connected then
        p_cnt.Connected := True;
      v_frm := TForm1.Create(Application);
      try
        v_frm.ADODataSet1.Connection := p_cnt;
        v_frm.ShowModal;
      finally
        FreeAndNil(v_frm);
      end;
    end;exports
    f_showform;exe中调用此函数,把主窗体的adoconnection1作参数传递过去
    如:
    procedure TForm1.Button1Click(Sender: TObject);
    var
      v_handle: HWND;
      v_point: Pointer;
      v_showform: procedure (p_cnt: TADOConnection;p_handle: HWND);stdcall;
    begin
      v_handle := LoadLibrary('project1.dll');
      v_point := GetProcAddress(v_handle,'f_showform');
      if v_point <> nil then
      begin
        v_showform := v_point;
        v_showform(ADOConnection1,Application.Handle);
      end;
      FreeLibrary(v_handle);
    end;
      

  4.   

    to:jiangshengyou said that "...if you have many users.",what that mean?
      

  5.   

    are you taking about that the Dll will be call by many process?
      

  6.   

    if the database is an online transaction processing database
    for data warehouse databases, there are not too many users, so fast-closing the connection is not necessary
      

  7.   

    如果有许多DLL,“connect string”是否恰当?