2

I using RemObjects Pascal Script component for Delphi XE, i've the following code:

type
  ITest = interface(IInterface)
  ['{7762A355-052F-449D-8347-01B59E2D2738}']
    procedure Execute;
  end;

  TTest = class(TInterfacedObject, ITest)
  private
    procedure Execute;
  end;


procedure TForm1.Button3Click(Sender: TObject);
var T: ITest;
    o: TPSScript;
begin
  T := TTest.Create;  

  o := TPSScript.Create(nil);
  try
    o.Script.Text :=
      'begin '                                    + sLineBreak +
      '  T.Execute; '                             + sLineBreak +
      'end.';
    Execute(o);
  finally
    o.Free;
  end;
end;


My question is how to register the interface variable T (instance of ITest) into pascal script so that I can invoke the T.Execute in pascal script?

lmengyew
  • 371
  • 4
  • 18

2 Answers2

2

first you need to register your interface type in the OnCompile event:

with ps.Compiler.AddInterface(ps.Compiler.FindInterface('IUnknown'), StringToGuid('{7762A355-052F-449D-8347-01B59E2D2738}'), 'ITest') do
  RegisterMethod('procedure Execute;', cdRegister);
ps.AddRegisteredVariable('data', 'ITest');

then in OnExecute:

SetVariantToInterface(ps.GetVariable('data'), mydata);
Carlo Kok
  • 1,128
  • 5
  • 14
  • 1
    Thanks for the code, but the ps.SetVarToInstance last parameter is cl: TObject, the "T" that i've created is ITest, any advices? – lmengyew May 31 '11 at 09:12
  • Could you take a look on [`this question`](http://stackoverflow.com/q/11453841/960757) if you can ? Sorry for spam, I'm willing to offer a bounty to resolve this. Thanks! – TLama Jul 12 '12 at 16:19
0

It's described on their wiki, here the article. Maybe somebody can summarize it, who is into this stuff. I just found it through google.

ba__friend
  • 5,783
  • 2
  • 27
  • 20