1

How one is supposed to "inject interface implementation" into script? Say I define an interface type in TdwsUnit, like

IFoo = interface
  procedure Bar;
end;

now how can I implement an function which returns array of IFoo (or List of IFoo or even single IFoo for that matter) in the script?

I tryed to add an IFoo item to the Instances collection of the unit but that resulted in error:

Syntax Error: TdwsUnit: "uTest" -- TdwsInstance: "tmp" -- AutoInstantiate is true but DataType "IFoo" is not a class

Creating an variable of IFoo type compiles, and it's OnReadVar event fires, but what I'm supposed to return there as value?

I guess I could define a class for each interface and then create instances of those classes but it seems kinda roundabout way as I don't need the classes per se, I just want to expose information to the script via interface types... so is there a way to return an array of "interface instances" to the script?

UPDATE

So, I have figured out how to return an array from Delphi side to script side, now I need to find a way to create the "interface instances" to put into the result array... What I have so far:

In the descendant of TdwsUnit I create an function (actually a method but I guess thats irrelevant)

meth := typClass.Methods.Add;
meth.Name := 'GetData';
meth.ResultType := 'array of String';
meth.OnEval := H_EvalFnc_GetData;

and then in the OnEval

procedure TMyUnit.H_EvalFnc_GetData(Info: TProgramInfo; ExtObject: TObject);
begin
  Info.ResultVars.Member['Length'].Value := 2;
  Info.ResultVars.Element([0]).Value := 'Hello';
  Info.ResultVars.Element([1]).Value := 'Word';
end;

Now I need to change the result type to array of IFoo and figure out how to create array elements in the OnEval hadler... any hints on how to that are welcome.

ain
  • 22,394
  • 3
  • 54
  • 74
  • Do you use the latest unstable version of DWS? AFAIR interfaces marshalling has just being added. And please show the code in which you bind your interface. – Arnaud Bouchez May 21 '13 at 18:38
  • @ArnaudBouchez Yes, I got the latest version from svn after your comment in newsgroup. I don't have any code to show, I'm total DSW newbie and not quite sure how this thing works... As I wrote in my question I tried to add an item to the instances collection but got error. So I quess my question is what's the correct way to "bind an interface"? – ain May 21 '13 at 19:03
  • The exposing is the there, but the marshalling isn't there yet. So currently you have to marshall manually through events on the Delphi side. – Eric Grange May 23 '13 at 08:12
  • @EricGrange Could you please post an example/explanation how to do it? I browsed throught demo projects but didn't found anything using interface types in that manner... – ain May 23 '13 at 08:29

0 Answers0