Thanks Rob for detailed explanation.
I am actually building a custom component and it can contain any number of
another component (for which I was thinking of makaing a collection). The
number of instances is decided by the caller of this component. So it is
possible that this collection may need to be exposed at design time also in
future.

Another constraint that you mentioned that collection item cannot exist
without collection, but I may require independent instances of the
collection item component as that is also a self contained class.

So in this view, I guess, best would be to create a brand new class from
TObject and have an Items property which if of the type ObjectList or a
simple array of my object and publish the Items, Get, etc properties.


Neha


On 1/6/06, Rob Kennedy <[EMAIL PROTECTED]> wrote:
>
> Neha Garg wrote:
> > have a doubt regarding which implementation is best, inheriting
> > TCollection, TObjectList or inheriting from TObject and using a property
> of
> > TList and expose functionality related to Add, Get etc.
> > With TCollection, the problem is that one has to write a TCollectionItem
> and
> > then the collection is bound with that Item only, you cannot have
> different
> > type of collections for different items.
>
> TCollection is only good if you need to expose the property at design
> time in the Object Inspector. Otherwise, you can always build a better
> collection class that does what you need without imposing the design
> restrictions that come with TCollection.
>
> The items in a TCollection cannot exist outside a TCollection. You
> cannot create a TCollectionItem without telling it which collection owns
> it. (You can move an item from one collection to another afterward.)
>
> When you descend from TList, remember that your class inherits
> *everything* about a TList, even the parts you might not want. You
> cannot hide a method, no matter how hard you try. TList is not a
> suitable base class if you intend to write a type-safe list. If I have a
> reference to your TList descendant, I can assign it to a variable of
> type TList and then add anything I want to it.
>
> If you want a type-safe list, then it should descend from a class that
> doesn't already provide list-like methods of its own. TObject is a good
> choice. Use a TList to help implement your custom list class, if you want.
>
> Consider how Contnrs.TOrderedList does not descend from TList. If it
> did, then it would have inherited TList's Insert method and Items
> property, which go against the idea of having a limited-access list.
>
> Only write a descendant class when you need to take advantage of the "is
> a" relationship between classes.
>
> --
> Rob
> _______________________________________________
> Delphi mailing list -> [email protected]
> http://www.elists.org/mailman/listinfo/delphi
>
_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi

Reply via email to