I need to use TStringList in dwscript.
In compiled delphi code I use both
sl := TStringList.Create;
and
sl := genSL;
where genSL creates and poulates the TStringList.
I would like to use this in dwscript but I have trouble returning a TStringList from genSL.
Apparently there are two approaches.
1 using RTTI
In delphi I write
dwsUnit1.Dependencies.Add(RTTI_UnitName);
dwsUnit1.Functions.Add('genSL', 'RTTIVariant');
and in the callback
procedure TMainForm.genSLEval(info: TProgramInfo);
var
sl: TStringList;
begin
sl := TStringList.Create;
// populate sl
Info.ResultAsVariant := TdwsRTTIVariant.FromObject(sl);
end;
This does allow my the pass an externally created TStringList into the script.
Problem: In the script I need to declare the list as RTTIVariant.
This is misleading as it actually is a TStringList (also I would like to use existing code without modification). I would prefer to declare the List as TStringList in the script.
2 Exposing TStringList to dwsUnit
In delphi I write
dwsUnit1.ExposeClassToUnit(TPersistent, TObject);
dwsUnit1.ExposeClassToUnit(TStrings, TPersistent);
dwsUnit1.ExposeClassToUnit(TStringList, TStrings);
In the script I can create and use TStringList.
But I can't declare a magic function that returns something TStringList-y
delphi code:
dwsUnit1.Functions.Add('genSL', 'TStringList');
and scriptcode:
var sl: TStringList;
sl := genSL;
Problem: this will abort script compilation with Syntax Error: Incompatible types: Cannot assign "TStringList" to "TStringList"
I assume I'm missing something. What is necessary to either
- Declare an Object as something other than RTTIVariant to pass objects to it
or
- Introduce a type so it can be passed into the script?
I'm using Delphi 2010 with dwscript-svn checked out back in 2013-07 (recent svn didn't compile in d2010). Any suggestions are appreciated.