In have a Delphi application running a DWS script. The Delphi application exposes an object instance, let's call it "MyApplication", to the script. The exposed object has a method which has one argument being a procedure.
Fundamentally by goal is to have a Delphi method doing some computation and stopping this computation when a callback procedure says it is done. The callback procedure is Inside the script.
I have implemented this by passing the name of the callback function as a string. It works nicely except that no type checking is done at script compile time. I would like to pass an actual procedure so that the script compiler can catch any error at compile time.
How to do that?
To help the reader understand what I mean, I show some - not working - code:
First a simplified verion of the Delphi side:
Interface
type
TAppCheckProc = procedure (var Done : Boolean);
TMyApplication = class(TPersistent)
published
procedure Demo(CheckProc : TAppCheckProc);
end;
Implementation
TMyApplication.Demo(CheckProc : TAppCheckProc);
var
Done : Boolean;
begin
Done := FALSE;
while not Done do begin
// Some more code here...
CheckProc(Done);
end;
end;
Second, on the script side I have this (Also simplified):
procedure CheckProc(
var Done : Boolean);
var
Value : Integer;
begin
DigitalIO.DataIn(1, Value);
Done := (Value and 8) = 0;
end;
procedure Test;
begin
MyApplication.Demo(CheckProc);
end;
It is likely that Demo method argument should be declared differently and should be called differently. That is the question...
Edit: Removed extra Tag argument (Error when simplified the code, this is not the question).