unit uDYLIBTestAPP;
{$mode objfpc}{$H+}
interface
uses
Classes,
SysUtils,
Forms,
Controls,
Graphics,
Dialogs,
Buttons,
StdCtrls;
type
{ TfDylibTestApp }
TfDylibTestApp = class(TForm)
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
BitBtn3: TBitBtn;
Memo1: TMemo;
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure BitBtn3Click(Sender: TObject);
private
public
end;
const
// Windows DLL Names
{$IFDEF MSWINDOWS}
TestDLL = 'pdylibtest.dll';
{$ENDIF MSWINDOWS}
// macOS DYLIB Names
{$IFDEF DARWIN}
TestDLL = 'pdylibtest';
{$ENDIF DARWIN}
{$IFDEF MSWINDOWS}
function say_Hello(Hello: string): boolean; stdcall; external TestDLL Delayed;
{$ENDIF MSWINDOWS}
{$IFDEF DARWIN}
function say_Hello(Hello: string): boolean; cdecl; external TestDLL;
{$ENDIF DARWIN}
function localFunction(localIn: string; out localOut: string): boolean;
var
fDylibTestApp: TfDylibTestApp;
implementation
function localFunction(localIn: string; out localOut: string): boolean;
begin
LocalOut := 'This was passed to the function: ' + LocalIn;
Result := True;
end;
{$R *.lfm}
{ TfDylibTestApp }
procedure TfDylibTestApp.BitBtn3Click(Sender: TObject);
begin
// Quit the test application
close;
end;
procedure TfDylibTestApp.BitBtn2Click(Sender: TObject);
var
sOut: string;
begin
// This is a local function
ShowMessage('Local Function Call');
if localFunction('Local in', sOut) then
showmessage('Local Function: TRUE (' + sOut + ')')
else
showmessage('Local Function: FALSE');
end;
procedure TfDylibTestApp.BitBtn1Click(Sender: TObject);
var
b:boolean;
sType: string;
sDLLString: string;
begin
b := False;
// Call the DLL Function
{$IFDEF MSWINDOWS}
sType := 'Windows DLL';
sDLLString := 'The string passed to the Windows DLL';
b := say_Hello(sDLLString);
{$ENDIF MSWINDOWS}
{$IFDEF DARWIN}
sType := 'macOS DYLIB';
sDLLString := 'The string passed to the macOS DYLIB';
b := say_Hello(sDLLString);
{$ENDIF DARWIN}
if b then
showmessage('Returned From: ' + sType + ': TRUE')
else
showmessage('Returned From: ' + sType + ': FALSE');
end;
end.