How do I pass an object as a parameter from Delphi code to a Fastscript function?
Given a Fastscript function like this:
function IsObjValid(obj: TSomeObject): boolean;
begin
Result := (obj.GetValue <> 0);
end
;
I want to call this function from my Delphi code passing a TSomeObject instance. Therefore I register the TSomeObject class like this:
type
TSomeObject = class end;
// ...
cl := FScript.AddClass(TSomeObject, 'TObject');
cl.AddMethod('function GetValue: integer', MethodSomeObjectGetValue);
... and call it like this:
FCurrentObj := TStringList.Create;
res := FScript.CallFunction('CheckInstance', Integer(FCurrentObj));
In MethodSomeObjectGetValue I expect Instance to be the value I passed as parameter above:
function TMyStript.MethodSomeObjectGetValue(Instance: TObject; ClassType: TClass;
const _MethodName: string; Caller: TfsMethodHelper): Variant;
begin
// function GetValue: integer
Assert(Integer(_Instance) = Integer(FCurrentObj), 'invalid Instance value');
// .... more code
end;
But it is always NIL, so I must be doing something wrong, but what?
Comments
Try to use TSomeObject(Integer(FCurrentObj))