[fpc-pascal]Dynamic Variables
Brad Campbell
brad at seme.com.au
Fri Aug 31 06:38:31 CEST 2001
G'day all..
Using fpc in OBJPAS mode I manipulate variables like this..
Type
TTheRec = Record
A : String[80];
B : Cardinal;
End;
PTheRec = ^TTheRec;
Var
DynArray : PTheRec;
Begin
GetMem(DynArray,SizeOf(TTheRec)*30);
DynArray[1].A := 'Hello';
DynArray[2].B := 42;
FreeMem(DynArray,SizeOf(TTheRec)*30);
End;
Under Mode Delphi, I have to do this..
Type
TTheRec = Record
A : String[80];
B : Cardinal;
End;
PTheRec = Array [1..(MaxInt Div SizeOf(TTheRec))-1] of TTheRec;
Var
DynArray : ^PTheRec;
Begin
GetMem(DynArray,SizeOf(TTheRec)*30);
DynArray[1].A := 'Hello';
DynArray[2].B := 42;
FreeMem(DynArray,SizeOf(TTheRec)*30);
End;
Is this the best way ?
--
Brad....
/"\
Save the Forests \ / ASCII RIBBON CAMPAIGN
Burn a Greenie. X AGAINST HTML MAIL
/ \
More information about the fpc-pascal
mailing list