1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
| unit CallDll1_MainForm;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Buttons,
Vcl.Samples.Spin,
CallDll1_Wrapper;
type
TCallDll1MainForm = class(TForm)
SpinEditA: TSpinEdit;
SpinEditB: TSpinEdit;
btnSomme: TButton;
btnSommeConstante: TButton;
procedure btnSommeClick(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure btnSommeConstanteClick(Sender: TObject);
private
{ Déclarations privées }
FMaDLL: TDLL1;
public
{ Déclarations publiques }
end;
var
CallDll1MainForm: TCallDll1MainForm;
implementation
{$R *.dfm}
procedure TCallDll1MainForm.btnSommeClick(Sender: TObject);
begin
// Si l'on a déjà chargé la DLL, on a conservé le contexte d'appel
if not Assigned(FMaDLL) then
FMaDLL := TDLL1.Create('DLL1.dll');
// SpinEditA c'est en réalité Self.SpinEditA, c'est implicite
// Self est l'instance en cours de TCallDll1MainForm,
// Comme TCallDll1MainForm a une pro
ShowMessageFmt('%d + %d = %d', [SpinEditA.Value, SpinEditB.Value, FMaDLL.Somme(SpinEditA.Value, SpinEditB.Value)]);
end;
procedure TCallDll1MainForm.btnSommeConstanteClick(Sender: TObject);
var
variableA, variableB : Integer;
begin
if not Assigned(FMaDLL) then
FMaDLL := TDLL1.Create('DLL1.dll');
variableA := 10; // SpinEditA.Value;
variableB := 20; // SpinEditB.Value;
ShowMessageFmt('%d + %d = %d', [variableA, variableB, FMaDLL.Somme(variableA, variableB)]);
end;
procedure TCallDll1MainForm.FormDestroy(Sender: TObject);
begin
FreeAndNil(FMaDLL);
end;
end. |
Partager