Link to home
Start Free TrialLog in
Avatar of gardenia
gardenia

asked on

Can I use Pointer as an Array in pascal like C++?

I want to use an FileMaping Pointer as an Array of Record,
But I dont know how to do that,somebody help me?
ASKER CERTIFIED SOLUTION
Avatar of AvonWyss
AvonWyss
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of edey
edey

Just adding a little to AvonWyss's comment:

The delphi runtime declares pointers to a couple of similar arrays (ex: PByteArray, PCharArray) that are often used, in D2 & D3 in particular, to approximate dynamicaly resizable arrays. They're declared like so (I don't have the source handy, but if my implementation isn't detail perfect, the concept stands):

TByteArray = array[0..32767] of byte;
PByteArray - ^TByteArray;

so you can do this:

var
 bytes : PByteArray;
 index : integer;
begin
 getMem(bytes,1000);//now we've got 0..999 elements
 index := 999;
 bytes[index] := random(256);//bytes[999] is now in 0..255
 dispose(bytes);


So you can extend this like so:

RMyRec = record
 fooStr : array[0..10] of char;
 fooInt : integer;
end;
TMyRecArray = array[0..some_big_number] of RMyRec;
PMyRecArray = ^TMyRecArray;

var
 recs : PRecArray;
 ix : integer;
begin
 getMem(recs,sizeOf(RMyRec)*100);//For an array of 0..99 Records
 

GL
Mike
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
gardenia:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

split points between AvonWyss and TOndrej

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Thanks,

geobul
EE Cleanup Volunteer