On Wed, 11 Jul 2001, Prof. A Olowofoyeku (The African Chief) wrote:
On 10 Jul 2001, at 18:24, Adam Naumowicz wrote:
Hello,
I have a basic question concerning strings and array memory representation in GPC. To my amusement I noticed that in the following program the string assigned to an array element cannot be then restored from the array itself. So probably an array of strings is not represented in memory just like an array of simple type, and cannot (?) be simply getmem-ed ?
program test; type NameStr=String[8]; shortarray=array[1..3] of NameStr;
var n:NameStr; a:^shortarray; i:integer;
begin getmem(a,3*sizeof(NameStr));
This is your problem. Use 'New' instead of 'getmem' - i.e., New (a, 3 * sizeof (NameStr)); or New (a, sizeof (shortarray)); or better still, just "New (a);"
Thanks for your answers. But I want my sources to stay BP/Delphi compatible... I still don't know what is wrong with the getmem call. Maybe I should try this example with a newer compiler as Maurice says it works fine for him. It worked fine for me with BP, Delphi and FPC, but all those handle strings in somewhat different manner than GPC. Why is new better than getmem in this example ? Regards, Adam Naumowicz
-------------------------------------- WWW: http://math.uwb.edu.pl/~adamn/ --------------------------------------