TCollection class bug

Here is an example script (tested under Delphi 7):

var
a : TCollection;
b : TCollectionItem;
begin
a:=TCollection.Create;
b:=a.Add; {Access violation at runtime here}
end.

Hello,
Constructor of TCollection is not registered in PascalScript. You should do it manually:

//We should create own constructor to create TCollection object with TCollectionItem items.
type TMyCollection = class (TCollection)
constructor Create();
end;

constructor TMyCollection.Create();
begin
inherited Create(TCollectionItem);
end;

// TPSScript.OnCompile
procedure TForm1.psOnCompile(Sender: TPSScript);
begin
Sender.Comp.FindClass(‘TCollection’).RegisterMethod(‘constructor Create’);
end;

//TPSScript.OnExecImport
procedure TForm1.psOnExecImport(Sender: TObject; se: TPSExec;
x: TPSRuntimeClassImporter);
begin
with x.Add(TCollection) do
begin
RegisterConstructor(@TMYCOLLECTION.CREATE, ‘CREATE’);
end;
end;

Thank you, this worked.