AnyDAC
ContentsIndexHome
PreviousUpNext
TADCustomConnection.SharedCliHandle Property

CLI handle shared with other connection.

Group
Links

Use SharedCliHandle, to set shared DBMS Call Level Interface connection handle, returned by other connection CliHandle property. This is useful to transfer connection from an application into a DLL. See DLL Development. Note, a connection cannot be shared with other process, as the sharing works only inside the same address space. 

After setting Connected=True for this connection, it will use the same physical DBMS connection / session as other connection. And will share the same transaction state. 

After setting Connected=False, this DLL connection will not release connection resources to the DBMC client. The application connection is responsible for resources releasing. Because that the application connection must be closed after closing all of the sharing connections.

property SharedCliHandle: Pointer;

See demo application AnyDAC\Samples\Comp Layer\TADConnection\DLL_Sharing.

Application code (without checks):

  FhDll := LoadLibrary(PChar('Project2.dll'));
  @FpShowData := GetProcAddress(FhDll, PChar('ShowData'));
  FpShowData(ADConnection1.CliHandle);

DLL code:

procedure ShowData(ACliHandle: LongWord);
begin
  ADConnection1.SharedCliHandle := ACliHandle;
  ADConnection1.Connected := True;
  ADQuery1.Active := True;
end;
What do you think about this topic? Send feedback!