Sharing an ADO Connection Through a DLL Border

We would like to share ADOConnection across the DLL boundary (Delphi in Delphi at the moment, although there may also be C # for Delphi in the near future).

As we would like to flexibly call DLLs from C # in the future, we hoped that we could define a DLL call using _Connection as a parameter. Sort of:

procedure DoStuff (ADOConnection: _Connection)
var
  InnerConnection: TADOConnection;
begin
  InnerConnection := TADOConnection.create(nil);
  try
    InnerConnection.ConnectionObject := ADOConnection;
    DoMoreStuff(InnerConnection);
  finally
    InnerConnection.free;
  end;
end;

Unfortunately, the TADOConnection destructor code closes the connection passed to it, which is an undesirable side effect. Adding

InnerConnection.ConnectionObject := nil

before free does nothing as it falls on

if Assigned(Value) = nil

in TADOConnection.SetConnectionObject, which causes the call to do nothing.

? , , . TADOConnection - , .

: / TADOConnection .Open, ( , , , " " MS UDL)

+4
1

:

  type TInit_StFattDLL = procedure( var DataBase:TAdoConnection);
  var  Init_StFattDLL:TInit_StFattDll;

:

Function ConnectDll():Boolean;
var
  handleDll:THandle;

begin
    handleDll := LoadLibrary('mydll.DLL');
    @Init_StFattDLL := GetProcAddress(handleDll , 'myConnectFunction');

      if @Init_StFattDLL <> nil then   
        begin
          Init_StFattDLL(ADOConnection1);
          result:=true;
         end
      else
         result:=false;
end;

dll :

:

Exports myConnectFunction;

:

var Database:TAdoConnection;

:

procedure myConnectFunction( var MyDataBase:TAdoConnection);export;
begin
   Database:=MyDataBase;
end
0

All Articles