# TCollection class bug

**URL:** https://talk.remobjects.com/t/tcollection-class-bug/297
**Category:** Pascal Script
**Created:** [October 24, 2011, 7:21pm UTC](https://talk.remobjects.com/t/tcollection-class-bug/297 "2011-10-24T19:21:52Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![dimako](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/d/77aa72/32.png) [@dimako](https://talk.remobjects.com/u/dimako)
#### Post date: [October 24, 2011, 7:21pm UTC](https://talk.remobjects.com/t/tcollection-class-bug/297/1 "2011-10-24T19:21:52Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![vovanl](https://talk.remobjects.com/user_avatar/talk.remobjects.com/vovanl/32/51_2.png) [@vovanl](https://talk.remobjects.com/u/vovanl)
#### Post date: [October 27, 2011, 9:59am UTC](https://talk.remobjects.com/t/tcollection-class-bug/297/2 "2011-10-27T09:59:46Z")

</div>

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](https://TPSScript.OnExecImport)  
procedure TForm1.psOnExecImport(Sender: TObject; se: TPSExec;  
x: TPSRuntimeClassImporter);  
begin  
with x.Add(TCollection) do  
begin  
RegisterConstructor(@TMYCOLLECTION.CREATE, ‘CREATE’);  
end;  
end;

---

<div class="post-metadata">

### Author: ![dimako](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/d/77aa72/32.png) [@dimako](https://talk.remobjects.com/u/dimako)
#### Post date: [October 28, 2011, 5:43pm UTC](https://talk.remobjects.com/t/tcollection-class-bug/297/3 "2011-10-28T17:43:18Z")

</div>

Thank you, this worked.
