?
Solved

Problems with TCollection

Posted on 1997-03-18
1
Medium Priority
?
197 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 100 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

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.

Question has a verified solution.

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

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…
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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses
Course of the Month8 days, 13 hours left to enroll

765 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