Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Problems with TCollection

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

609 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