Solved

Problems with TCollection

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

758 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

22 Experts available now in Live!

Get 1:1 Help Now