Board index » delphi » TLists can they hold RECORDS ?

TLists can they hold RECORDS ?

Can TLists hold RECORDS in the same way as TCollections?  If not, what
is the Delphi way of holding disparate information as you can get in a
RECORD?  Do all integer types have to be reduced to string so that a
columnar listing of data can be created?  And finally are there any
sites that help newbies to Delphi but have a background in TP7?

Regards,
John
--
John Matthews

 

Re:TLists can they hold RECORDS ?


records - yup... (sort of).
You just need to use dynamic records and store their pointers in the
List.

integer types - you can easily create a descendant of TList to handle
integer types (TIntegerList).  The Add method can auto-convert to text
for display. (unless you use a table that has an integer field, but the
bottom line is, even they have to convert to text for displaying).

Get a couple of good books.  I also came from BP7, it's really no
differant (if you used BP objects).  Borland made a good "How to" book
that had some good tricks.

Hope it helps,
Mark

John Matthews says...

Quote

> Can TLists hold RECORDS in the same way as TCollections?  If not, what
> is the Delphi way of holding disparate information as you can get in a
> RECORD?  Do all integer types have to be reduced to string so that a
> columnar listing of data can be created?  And finally are there any
> sites that help newbies to Delphi but have a background in TP7?

> Regards,
> John
> --
> John Matthews

Re:TLists can they hold RECORDS ?


Quote
John Matthews wrote:

> Can TLists hold RECORDS in the same way as TCollections?  If not, what
> is the Delphi way of holding disparate information as you can get in a
> RECORD?  Do all integer types have to be reduced to string so that a
> columnar listing of data can be created?  And finally are there any
> sites that help newbies to Delphi but have a background in TP7?

> Regards,
> John
> --
> John Matthews

Not Sure, but I believe you could use a typed array..

If your record type is defined like:

TMyLocationRecord = Record
 Left,
 Right,
 Top,
 Bottom : TPoint;
end;

MyLocationArray : array[0..100] of TMyLocationRecord;

Then use New, to create a new instance of the record, and then just
assign it as an array element:

MyLocationArray[0] = MyNewRecord;

Hope that helps!

Rkr

--
                   \|||/
                   /'^'\
                  ( 0 0 )
--------------oOOO--(_)--OOOo--------------
. Reid Roman                              .
. Delphi Programmer / Analyst             .
. TVisualBasic:=class(None);              .
. May the Source be With You              .
-------------------------------------------
. Auto-By-Tel (http://www.autobytel.com)  .
. Irvine, CA U.S.A                        .
. E-Mail : rkroman (at) pacbell (dot) net .
. or reidr (at) autobytel (dot) com       .
-------------------------------------------

Re:TLists can they hold RECORDS ?


Quote
Reid Roman wrote:

> John Matthews wrote:

> > Can TLists hold RECORDS in the same way as TCollections?  If not, what
> > is the Delphi way of holding disparate information as you can get in a
> > RECORD?  Do all integer types have to be reduced to string so that a
> > columnar listing of data can be created?  And finally are there any
> > sites that help newbies to Delphi but have a background in TP7?

TLists are variable-sized one-dimensional arrays of pointers.  They do
not own nor do they actually dispose of what they point to.

The TCollection object and several others have been effectively ported
to Delphi, both in freeware and in various commercial offerings.

Re:TLists can they hold RECORDS ?


Yes - first declare a pointer to the record - eg:

PSomeRec = ^TSomeRec;
TSomeRec = record
  FirstField: integer;
  SecondField: string;
end;

Charles Johnson

Other Threads