Board index » delphi » Novice Needs Help to get around array size limit

Novice Needs Help to get around array size limit

        I'm trying to find a way set up an array at least 3,000
records or objects.  I don't know how to get around
the 64k array size limit.  I'v read through the entire Users Guide,
 Delphi by Example, and Delphi for Dummies.  I tried attaching
objects to a string list,  but the objects were not saved to disk
 along with the disk.  Also got a type mismatch when I tried to
 read them out into the same object type.
         I'm familiar with Basic and (School-book) C++, so if you
could just point in the right direction...  I think what I need
 is something called a container class,  but I havn't seen
anything like that in the three books I'v read so far.  
(I intend to pick up Delphi Unleashed soonest.)  

 

Re:Novice Needs Help to get around array size limit


Quote
James Fynmore (f...@icon.net) wrote:

:       I'm trying to find a way set up an array at least 3,000
: records or objects.  I don't know how to get around
: the 64k array size limit.  I'v read through the entire Users Guide,

The simplest way is to set up an array of pointers to the objects, and
allocate the objects on the heap.  If you get familiar with the New and
Dispose procedures or the GetMem/FreeMem procedures, you'll clear up most
problems relating to the 64K limitations.

Instead of accessing element A[1937], you will access element A[1937]^.
This will require some familiarity with typecasting.

type
MyRecType: record a,b,c:longint;D:array[1..200] of char;

the old way
var A: array[1..500] of MyRecType;

the new way
type PMyRecType:^MyRecType;
var A: array[1..500] of PMyRecType;

Using the pointer method, the array A only contains the addresses of its
components. It's up to you, using the memory allocation functions of your
choice, to manage the heap correctly.

Other Threads