?
Solved

How do I use TCollection?

Posted on 1997-04-19
6
Medium Priority
?
216 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses
Course of the Month13 days, 17 hours left to enroll

800 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