Solved

How do I use TCollection?

Posted on 1997-04-19
6
203 Views
Last Modified: 2010-04-04
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
Comment
Question by:Ajit
6 Comments
 
LVL 3

Expert Comment

by:mheacock
ID: 1335503
For five points I can tell you this....

   Increase the points for this question to at least 50 (if not more).
0
 
LVL 2

Expert Comment

by:gysbert1
ID: 1335504
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
 

Author Comment

by:Ajit
ID: 1335505
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 3

Expert Comment

by:mheacock
ID: 1335506
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
 
LVL 2

Expert Comment

by:gysbert1
ID: 1335507
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
 

Accepted Solution

by:
W. Yang earned 0 total points
ID: 1335508
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now