The Delphi used in this article is Embarcadero Delphi 2010. Any compiler and language can be used to make a DLL as long as the output is in flat “C”-type format (eg. No Objects, Classes or Strings, being passed as parameters or returned).
Step 1: Make the DLL in Delphi
Click File | New | Other | Dynamic Link Library
This is the code for a DLL named ESPL_DLL.
library ESPL_DLL;
const ESPL_NAME = ‘ESPL_DLL.DLL’;
{$R *.res}
function ESPL_Sum(AValue1: real; AValue2: real): real; stdcall;
begin
result := AValue1 + AValue2;
end;
function ESPL_Max(AValue1: real; AValue2: real): real; stdcall;
begin
if (AValue1 >= AValue2) then
result := AValue1
else
result := AValue2;
end;
exports
ESPL_Sum,
ESPL_Max;
begin
end.
Step 2: Make the ESPL Form
Here is the form in Ensign 10′s ESPL IDE, with 2 buttons and a memo component.
Step 3: Add the source code
{$FORM TfrmMain, Main.sfm}
uses Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;
function ESPL_Sum(AValue1: real; AValue2: real): real; stdcall; external ‘ESPL_DLL.dll’;
function ESPL_Max(AValue1: real; AValue2: real): real; stdcall; external ‘ESPL_DLL.dll’;
procedure btnSumClick(Sender: TObject);
var rValue: real;
begin
rValue := ESPL_Sum(3.5, 7.2);
Memo1.Lines.Add(rValue);
end;
procedure btnMaxClick(Sender: TObject);
var rValue: real;
begin
rValue := ESPL_Max(8.7, 10.1);
Memo1.Lines.Add(rValue);
end;
procedure frmMainShow(Sender: TObject);
begin
Memo1.Clear();
end;
begin
end;
Step 4: Run the program script
- Click the ESPL Run button
- Click the Sum button
- Click the Max button















