Solved

How do I use TCollection?

Posted on 1997-04-19
6
202 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 3

Expert Comment

by:mheacock
Comment Utility
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
Comment Utility
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
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 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

12 Experts available now in Live!

Get 1:1 Help Now