Question

(Note: This is somewhat related to my last question).

I am new to using TCollection in Delphi, and am still wrapping my head around the various ways to handle one-to-many class/property-item relationships. Exploring TCollection and TCollectionItem, I ran into a couple questions:

1) Is it possible to use TCollection or TOwnedCollection for a TForm property? (Haven't tried it yet, but am wondering in advance if its built-in Object Inspector capacities will cause problems).

2) If one ever wants to use some already-defined-elsewhere class, which can't directly descend from TCollectionItem, with TCollection (i.e. kind of "as" a "TCollectionItem"), can that be accomplished? If so, is that something one would accomplish via interfaces?... or what would be the best approach?

Was it helpful?

Solution

  1. For the object inspector, it does not matter on what component the properties are defined. Since a TForm descends from TComponent, it is possible.

  2. The easiest way is to write a wrapper class (lets call it W) around your already-defined-elsewhere class (lets call it A). Each instance of X owns and encapsulates A.

--jeroen

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top