How registrate two class with circular references in DWScript?

116 Views Asked by At

I need to register TCollection and TCollectionItem classes, but because of the properties of

{TCollection}
property Items [Index: Integer]: TCollectionItem
{TCollectionItem}
property Collection: TCollection

сonstantly raises the exception of the impossibility to find TCollectionItem/TCollectionItem type.

2

There are 2 best solutions below

1
DragonFlyOfGold On

If you register the class on you own within code, you could first register the TCollectionItem without the property Collection: TCollection, then register TCollection with property Items [Index: Integer]: TCollectionItem and afterwards adding the property Collection: TCollection to your TCollectionItem.

0
Toky Olivier Razanakotonarivo On

You can use:

type
  TCollection = class;

  TCollectionItem = class
  published
    property Items: TCollection;
  end;

  TCollection = class
  published
    property Items [Index: Integer]: TCollectionItem;
  end;