Site icon Embarcadero RAD Studio, Delphi, & C++Builder Blogs

Learn How To Use FireDAC In The Dynamic-Link Libraries With DLL Sharing Sample In Delphi

To this end, the sample uses the CliHandle and SharedCliHandle properties of the TFDConnection class.

Location

You can find the DLLSharing sample project at:

How to Use the Sample

  1. Navigate to the location given above and open Project1.dproj.
  2. Press F9 or choose Run > Run.

Files

File in DelphiContains
Project1.dproj
Project1.dpr
The project itself.
Unit1.pas
Unit1.fmx
The main form.
Project2.dproj
Project2.dpr
The DLL.
Unit2.pas
Unit2.fmx
The DLL form.

Implementation

The sample uses FireDAC to implement a connection with a dynamic-link library. To this end, the sample implements three buttons named: Button1Button2 and Button3. Each button handles a OnClick event to implement the following features:

Load DLL

To transfer a connection between an application and a DLL, the sample transfers the TFDCustomConnection.CliHandle property value to the DLL. The handle must be assigned to the TFDCustomConnection.SharedCliHandle property.

After the TFDCustomConnection.SharedCliHandle is assigned, the DLL connection can be activated by setting the Connected property to True. Note that there is no need to set up a connection definition, including DriverID.

[crayon-673fd0eb9da3d612109263/]

Show data

Then, the connection can be used as a normal database connection:

[crayon-673fd0eb9da46968460433/]

Unload DLL

To unload the dynimic-link library, the sample implements the following code:

[crayon-673fd0eb9da48983475183/]

Head over and check out the full sample source code for DLL sharing with FireDAC in Delphi.

Exit mobile version