Blockly test

This commit is contained in:
Michael Schimmel
2025-06-10 22:31:16 +02:00
parent 0e598d595e
commit 7516bd3d9d
9 changed files with 2089 additions and 0 deletions
+68
View File
@@ -0,0 +1,68 @@
unit LLVM.Runner;
interface
uses
System.SysUtils, Winapi.Windows, System.Classes;
type
// Callback-Prozedur, die von der DLL aufgerufen wird
TLogIntegerCallback = procedure( AValue: Integer ); stdcall;
// Signatur der exportierten DLL-Funktion
TStarteLogikProc = procedure( ALogCallback: TLogIntegerCallback ); stdcall;
type
TLLVMRunner = class
private
FModule: HMODULE;
FStarteLogik: TStarteLogikProc;
class var
FLog: TStrings;
class procedure LogInteger( AValue: Integer ); static; stdcall;
public
constructor Create(const ADLLPath: string);
destructor Destroy; override;
procedure Execute;
class property Log: TStrings read FLog write FLog;
end;
implementation
{ TLLVMRunner }
constructor TLLVMRunner.Create(const ADLLPath: string);
begin
inherited Create;
FModule := LoadLibrary( PChar( ADLLPath ) );
if FModule = 0 then
raise Exception.Create( 'Failed to load DLL.' );
FStarteLogik := GetProcAddress( FModule, 'StarteLogik' );
if not Assigned( FStarteLogik ) then
raise Exception.Create( 'Procedure "StarteLogik" not found in DLL.' );
end;
destructor TLLVMRunner.Destroy;
begin
if FModule <> 0 then
FreeLibrary( FModule );
inherited;
end;
procedure TLLVMRunner.Execute;
begin
if Assigned( FStarteLogik ) then
// Führe die DLL-Funktion aus und übergebe unsere Callback-Methode
FStarteLogik( LogInteger );
end;
// Dies ist die Methode, die die DLL aufruft.
// Sie muss "static" (class procedure) sein, um eine feste Adresse zu haben.
class procedure TLLVMRunner.LogInteger( AValue: Integer );
begin
if Assigned( FLOg ) then
FLog.Add( Format( 'DLL logged integer: %d', [AValue] ) );
end;
end.