uses WinCRT;
procedure TForm1.Button1Click(Sender: TObject);
var
MyArray: array[0..30] of char;
b: ^char;
i: integer;
begin
StrCopy(MyArray, 'Lloyd is the greatest!'); {get something to point to}
b := @MyArray; { assign the pointer to the memory location }
for i := StrLen(MyArray) downto 0 do
begin
write(b^); { write out the char at the current pointer location. }
inc(b); { point to the next byte in memory }
end;
end;
The following code demonstrates that the Inc() and Dec() functions
will increment or decrement accordingly by size of the type the pointer
points to:
var
P1, P2 : ^LongInt;
L : LongInt;
begin
P1 := @L; { assign both pointers to the same place }
P2 := @L;
Inc(P2); { Increment one }
{ Here we get the difference between the offset values of the
two pointers. Since we originally pointed to the same place in
memory, the result will tell us how much of a change occured
when we called Inc(). }
L := Ofs(P2^) - Ofs(P1^); { L = 4; i.e. sizeof(longInt) }
end;