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.