Link to home
Start Free TrialLog in
Avatar of Ajit
Ajit

asked on

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
Avatar of mheacock
mheacock

For five points I can tell you this....

   Increase the points for this question to at least 50 (if not more).
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
Avatar of Ajit

ASKER

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....
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,
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 !

ASKER CERTIFIED SOLUTION
Avatar of W. Yang
W. Yang

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial