Solved

Problems with TCollection

Posted on 1997-03-18
1
192 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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

737 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