I have recently read from a eBook named "Fearless Cross-Platform Development with Delphi" about developing a cross-platform dynamic library application. Therefore, I downloaded the sample source which has a Host and Library projects. The original library project contains one unit which only has one export function below:
library HideStringLib;
uses
{$IFDEF MSWINDOWS} ShareMem, {$ENDIF }
uHideStringFunc in 'uHideStringFunc.pas';
begin
end.
unit uHideStringFunc;
interface
{$IFDEF MACOS}
function HideString(const MyString: string): string; stdcall; export;
{$ENDIF}
exports HideString;
implementation
function HideString(const MyString: string): string; stdcall; export;
begin
// manipulate the string to hide its original contents
for var i := 1 to Length(MyString) do
Result := Result + Chr(Random(26) + Ord('A')) + MyString[i];
end;
end.
Host has a button clicked to call function below to load the library dynamically:
unit ufrmHideStringMain;
...
function TfrmHideStrMain.LoadLibFile: boolean;
begin
DllHandle := LoadLibrary(LIB_NAME);
if DLLHandle = 0 then
begin
lblHidden.Text := 'Could not find function library: ' + LIB_NAME;
btnHideString.Enabled := False;
end else begin
@HideString := GetProcAddress(DllHandle, '_HideString');
end;
end;
Initially, the original samples compiled and ran successfully in both Windows/MacOS environments.
In order to test using FMX in the library, I tried to modify the library unit (uHideStringFunc.pas) by adding FMX.Dialogs in the uses clause and a ShowMessage() statement in the HideString() function, and then rebuild.
The program runs OK on Windows, but terminates unexpectedly when run on MacOS. So, I ran the program in debug mode and get an Access Violation whenever LoadLibray() is called. The same incident happens if I add an FMX form in the library project.
Therefore, I would like to know, can a Dynamic Library for MacOS platform be built with FMX units? Or, is there a solution to fix this?