Discussion:
paramaterized generics?
(too old to reply)
Brian
2010-10-11 15:47:15 UTC
Permalink
Is there a way to create a list of a certain type of items?

myList : TList<myClass>

brian
Jamie
2010-10-11 19:58:36 UTC
Permalink
Post by Brian
Is there a way to create a list of a certain type of items?
myList : TList<myClass>
brian
Yes, use either Tlist or Tobjectlist, these will hold the instances
of your types.. Actually, you can put any type of class in there..

If you want only to hold a specific class.
Var
mylist :Array of TMyClass;

Something in the other of that..
Rudy Velthuis
2010-10-12 00:38:24 UTC
Permalink
Post by Brian
Is there a way to create a list of a certain type of items?
myList : TList<myClass>
Yes, using generics in Delphi 2009, 2010 or XE. Or in the .NET version
of Delphi 2007.
--
Rudy Velthuis http://rvelthuis.de

"t is not so much the suffering as the senselessness of it that
is unendurable."
-- Nietzsche
Rudy Velthuis
2010-10-12 00:38:26 UTC
Permalink
Post by Brian
Is there a way to create a list of a certain type of items?
myList : TList<myClass>
Yes, using generics in Delphi 2009, 2010 or XE. Or in the .NET version
of Delphi 2007.
--
Rudy Velthuis http://rvelthuis.de

"t is not so much the suffering as the senselessness of it that
is unendurable."
-- Nietzsche
a***@aol.com
2010-10-12 06:07:30 UTC
Permalink
Post by Brian
Is there a way to create a list of a certain type of items?
myList : TList<myClass>
If you want a list in which you have activities both on the list as a
whole, & on individual members of the list, then use descendants of
the TCollection / TCollectionItem pair. These two classes incorporate
a TList and the interactions of creating, indexing & accessing the
elements of the list.

They are used internally by Delphi in many cases.

Alan Lloyd
Rudy Velthuis
2010-10-12 12:07:54 UTC
Permalink
Post by a***@aol.com
Post by Brian
Is there a way to create a list of a certain type of items?
myList : TList<myClass>
If you want a list in which you have activities both on the list as a
whole, & on individual members of the list, then use descendants of
the TCollection / TCollectionItem pair. These two classes incorporate
a TList and the interactions of creating, indexing & accessing the
elements of the list.
Dunno. I'd rather write a simple wrapper for TObjectList exposing
routines that deal with MyClass instead of TObject. I don't like the
dependencies between TCollection and TCollectionItem.
Post by a***@aol.com
They are used internally by Delphi in many cases.
Only in the VCL.

And Delphi 2009 and above have generics, so there you can use TList<T>:

myList: TList<myClass>;
...
myList := TList<myClass>.Create;
--
Rudy Velthuis http://rvelthuis.de

"I was thrown out of college for cheating on the metaphysics
exam; I looked into the soul of the boy next to me."
-- Woody Allen.
Loading...