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))

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.