• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 223
  • Last Modified:

How do I use TCollection?

I'm new to Delphi, and need a heads-up using TCollection.  What I want to build is--eventually--a collection of collections, and here's how it may be written in VB:
------------------------------------------------------
Dim colParent as new collection
Dim colChild1 as new collection, colChild2 as new collection
Dim cmdBuf as new CommandButton

colChild1.add "apple", "foo"
colChild1.add cmdBuf, "somebutton"

colParent.add colChild1
colParent.add colChild2
---------------------------------------------------------

Notice that VB collections are heterogenous, and may be "keyed" to retrieve specific items.  VB collections are also pretty simple-minded to use.

Now in Delphi, please?  I'm sure as much or more is possible w/ TCollection.

Thanx
--Ajit
0
Ajit
Asked:
Ajit
1 Solution
 
mheacockCommented:
For five points I can tell you this....

   Increase the points for this question to at least 50 (if not more).
0
 
gysbert1Commented:
Some step by step instructions :

First :
  Increase you points to i'd say 150

Second :
  Give More details what Your example is very nice, but what do you intend to do with the application

Third:
  Wait for your answer patiently ...

Good Luck
0
 
AjitAuthor Commented:
That's 2 people advising me to increase points.  Hmmm.  Unfortunately, right now I don't think it is worth any more--what I'm after is a matter of usage model, and syntax.  More to the point, I'm sure to come up with the answer myself sooner or sooner.

I'm unsure why gysbert1 asked for applicability, since that's most likely irrelevant.  To explain, notice that all the VB example is doing is building a souped-up tree.  (Souped-up because the VB tree has syntactic support for referring to groups of nodes.)

Of course, I could write the same data-structure in Delphi since this language supports pointers, but I'm loathe to maintain memory and TCollection seems so enticingly convenient.  Hell, the VB2Delphi reference says TCollection is the Delphi analog of VB's Collection object....
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
mheacockCommented:
The only thing worth 5 points is a single URL.  You don't think
the question is worth more...fine...I've no complaint either
way...but it's pretty slim that you'll get a response concerning your question...though you may get more 'increase points' comments.

5 points insn't worth our time...and I've already spent 25 points worth of my time explaining this whole thing.

As for gysbert1 asking for applicability...I agree with you...I don't see how it would matter...unless he would want to suggest alternative methods for doing what you'd like to do...a lot of programmers like to push their own ideas on others, perhaps all programmers, since there are so many ways in which to do a single task.  I know I'm one of these people from time to time.  As I'm sure you are too.

Cheers,
0
 
gysbert1Commented:
The reason I asked for applicability is that I have ran into trouble using TCollection before. If your container only needs to hold a few items it can be nice since the access is pretty fast but it has some very annoying limits. Since TCollection uses an array of pointers, the array is limited to 64k. This is because the class comes from old Pascal (BP7, etc) which didn't know about flat memory models. Since each pointer uses 4 bytes it  leaves you with 16k entries max.

Now if your application needs more than 16k entries TCollection is definately a NO-NO ! It is almost always better practice to use something like a linked list to do containers. This unfortunately makes extensive use of pointers and objects and I gather from your comment you are not too hot on this.

Anyway. If I give you a decent answer (that is after a points increase) I would have to know this otherwise you will hate me when your first client calls and moans about an EIntOverflow !

0
 
W. YangCommented:
In delphi I always using TList to create a collection of objects, but you need to defined your own object base on TObject first.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now