Solved

Problems with TCollection

Posted on 1997-03-18
1
193 Views
Last Modified: 2010-04-04
I'm a new Delphi 2 user and I want rewrite some TPW programs in D2, but I don't know how the TCollection object works in D2.
My code in TPW is
Type
   PData = ^TData
  TData = Array[0..MaxPoint] of Real;
var
  MyCurve : TCollection;
  Data : PData;

begin
   Data:=New(PData);
   MyCurve:=New(PCollection,Init(10,2));
  ....
   MyCurve^.Insert(Data);
  ....
end.

What is the code in Delphi to do the same thing ?
Thank's for your help.

--
Jean-Louis LAVIE
<jean-louis.lavie@esa5017.u-bordeaux2.fr>

0
Comment
Question by:jllavie
[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
1 Comment
 
LVL 3

Accepted Solution

by:
mheacock earned 50 total points
ID: 1334892
[This is from the TCollections section fo the Delphi help file].
------------------------------------------------------------
The TCollection object is used to maintain a collection of TCollectionItem objects. TCollection maintains an index of the collection items in its Items array. The Count property contains the number of items in the collection. Use the Add and Clear properties to add new items to the collection or to delete items from the collection. Objects descended from TCollection can contain objects descended from TCollectionItem. Examples are in the TStatusBar and THeaderControl controls which use TStatusPanels and THeaderSections collection objects to contain TStatusPanel and THeaderSection collection items.

In addition to these properties, methods, and events, the TCollection object also has the methods that apply to all objects and is a direct descendent of TPersistent.
--------------------------------------------------------------

Just by looking at your code, it looks to me that a TList might better serve your purposes.  A TList keeps a list of pointers.  Since you want to store Reals (btw, the Real type is slowly being phased out and is incompatible with other programming languages, use Single, which is byte compatible with C/C++'s Float), the Tlist would store pointers to those real objects.

If you replace TList with TCollection in your code, the changes are very simple.

var
    MyCurve: TList;
    ...
begin
    ...
    MyCurve := TList.Create;
    ...
    MyCurve.Add(Data);
    ...
    Data := TData(MyCurve.Items[n]);
end;
0

Featured Post

Technology Partners: 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!

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
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.

717 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