0

(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?

Community
  • 1
  • 1
Jamo
  • 3,238
  • 6
  • 40
  • 66
  • 1
    If you have two questions on SO, you should separate them into **two separate questions**, unless they are inextricably linked. – Argalatyr Sep 19 '09 at 03:37
  • BTW, I think Nick Hodges directly answered #1 in your prior question here: http://stackoverflow.com/questions/548567/array-property-tlist-tstringlist-or-tcollection-etc-delphi-win32/548596#548596 – Argalatyr Sep 20 '09 at 15:59
  • @Argalatyr - Noted re: 2 questions. In my situation/instance they felt quite linked, but I can see how one might think otherwise, and note the exhortation.

    re: #1, Nick's answer addressed TCollection (and was largely why I was exploring that option), but I wasn't sure if design-time, Object-Inspector aspects might be different for TForms than other components. Jeroen answers the question below.
    – Jamo Sep 21 '09 at 20:38

1 Answers1

2
  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

Jeroen Wiert Pluimers
  • 23,965
  • 9
  • 74
  • 154