I am having difficulty reacting to events within my pascal script.
Is it possible, within a script, to assign a script function or procedure to execute on an event declared in a class that has been imported via PS Unit Importer ? I want to do this within a script, not having to do it in code before calling script. When I try to set an event within the script, I get an error that I have the wrong number of parameters? I have something
like the following:
type
TMyEvent = procedure(const AIdent: string) of object;
type
TMyClass = class
private
FMyEvent : TMyEvent;
..
protected
procedure DoMyEvent(const AIdent: string);
public
property MyEvent: TMyEvent read FMyEvent write FMyEvent;
end;
procedure TMyClass.DoMyEvent(const AIdent: string);
begin
if Assigned(FMyEvent) then
FMyEvent(AIdent, AValue);
end;
//The above DoMyEvent gets called within my code when the event fires
================= in my script ========================
procedure wow(AIdent : string);
begin
// it worked!
...
end;
var TC: TMYCLASS;
begin
TC := TMYCLASS.create;
TC.MyEvent := wow;
why doesn’t this work ? I get an error that I have wrong number of params?
also:
I have seen the following function on a couple of websites saying that it allows what I am talking about.
procedure LinkMethod(SourceMethodName: String; Instance: TObject; ScriptMethodName: String);
var
ScriptMethod: TMethod;
begin
ScriptMethod := ScriptEngine.GetProcMethod(ScripMethodName);
SetMethodProp(Instance, SourceMethodName, ScriptMethod);
end;
If so, how would I use it, if not, what is a better way?
Thanks, I hope I gave enough info
Ken