Ok, Ive had a look for what its worth. It seems all constructors are broken. I had a look in uPSRuntime & x86.inc which includes a lot of FPC specific edits to handle FPC constructor calling conventions, all of which are beyond my knowledge.
So, I came up with two work arounds:
1) Create an external function which creates the TStringList. ie:
function CreateStringList: TStringList;
begin
Result := TStringList.Create;
end;
procedure TForm1.PSScript1Compile(Sender: TPSScript);
begin
PSScript1.AddFunction(@ShowMessage, 'procedure ShowMessage(m: string);');
PSScript1.AddFunction(@CreateStringList, 'function CreateStringList: TStringList;');
end;
Then this code works:
var
s: TStringList;
begin
ShowMessage('This line works.');
s := CreateStringList;
s.Add('Test');
ShowMessage(s[0]);
s.Free;
end.
But, it still will crash if you call the constructor. So:
2) Register a constructor for TStringList which links to the CreateStringList function:
procedure TForm1.PSScript1CompImport(Sender: TObject; x: TPSPascalCompiler);
begin
x.FindClass('TStringList').RegisterMethod('constructor Create');
end;
procedure TForm1.PSScript1ExecImport(Sender: TObject; se: TPSExec; x: TPSRuntimeClassImporter);
begin
x.FindClass('TStringList').RegisterConstructor(@CreateStringList, 'Create');
end;
This "shouldn't" work but it does for some reason.
Im guessing someone with more knowledge of FPC constructor calling needs to look at this issue. But, there are 2 workarounds.