Call method from script, that returns some value?

Hello there,

i’m trying to get familiar with Remobjects Script.NET. I managed to register some objects and methods, but i didn’t get it to work registering a method that returns some result…

Isn’t it possible to call methods returning something, or am i doing it wrong?

namespace RemScriptTest;

interface

type
  ConsoleApp = class
  public
    class method Main(args: array of String);
  end;

  TestMethods = public class
  public
    class method ReadText: String;
    class method WriteText(text: String);
    method ReadInteger: Int32;
  end;

  ReadIntegerBlock = block: Int32;
  ReadTextBlock = block: String;
  WriteTextBlock = block(text: String);

implementation

class method ConsoleApp.Main(args: array of String);
begin
  var script := new RemObjects.Script.EcmaScriptComponent;
  var tm := new TestMethods;
     
  script.ExposeType(typeOf(TestMethods), 'TestMethods');
  script.Globals.SetVariable('WriteText', new WriteTextBlock(TestMethods.WriteText)); 
  script.Globals.SetVariable('ReadInteger', new ReadIntegerBlock(tm.ReadInteger));
  script.Globals.SetVariable('ReadText', new ReadTextBlock(TestMethods.ReadText));

  script.Source := "TestMethods.WriteText('1: Hello World!');";
  script.Run;

  script.Source := "WriteText('2: Hello World!');";
  script.Run;

  script.Source := "var s = TestMethods.ReadText; WriteText('3: ' + s);";
  script.Run;

  script.Source := "var s = ReadText; WriteText('4: ' + s);";
  script.Run;

  script.Source := "var o = new TestMethods; var x = o.ReadInteger; WriteText('5: ' + x);";
  script.Run;

  script.Source := "var x = ReadInteger; WriteText('6: ' + x);";
  script.Run;

  Console.ReadKey;
end;

class method TestMethods.ReadText: String;
begin
  exit Console.ReadLine;
end;

class method TestMethods.WriteText(text: String);
begin
  Console.WriteLine(text);
end;

method TestMethods.ReadInteger: Int32;
begin
  exit 42;
end;

end.

The program above will output the following result:

1: Hello World!
2: Hello World!
3: RemObjects.Script.EcmaScript.Overloads
4: RemScriptTest.ReadTextBlock
5: RemObjects.Script.EcmaScript.Overloads
6: RemScriptTest.ReadIntegerBlock

Best regards,

Timm

When calling a function in js you have to use () after it.

So few words, so much pain… what a shame.

Sorry for wasting your time!