// Test integer pointer
procedure TForm1.Button1Click (Sender: TObject);
var
  p: PInteger;
  i: Integer;
begin
{$ POINTERMATH ON}
  // write
  p: = GetMemory (SizeOf (Integer) * 4);
  p [0]: = 11;
  p [1]: = twenty two;
  p [2]: = 33;
  p [3]: = 44;

  // read
  ShowMessageFmt ('% d,% d,% d,% d', [p [0], p [1], p [2], p [3]]);
{$ POINTERMATH OFF}

  // Sometimes it was so troublesome
  ShowMessageFmt ('% d,% d,% d,% d', [p ^, PInteger (Integer (p) + SizeOf (Integer) * 1) ^,
    PInteger (Integer (p) + SizeOf (Integer) * 2) ^,
    PInteger (Integer (p) + SizeOf (Integer) * 3) ^]);

  FreeMemory (p);
end ;

// Test structure pointer
procedure TForm1.Button2Click (Sender: TObject);
type 
  TMyRec =record 
    Name:string [12];
    Age: Word;
  end ;
var
  p: ^ TMyRec;
begin
{$ POINTERMATH ON}
  p: = GetMemory (SizeOf (TMyRec) * 2);

  // write
  p [0] .Name: = 'Zhang San';
  p [0] .Age: = 11;
  p [1] .Name: = 'Li Si';
  p [1] .Age: = twenty two;

  // read
  ShowMessageFmt ('% s,% d', [p [0] .Name, p [0] .Age]);
  ShowMessageFmt ('% s,% d', [p [1] .Name, p [1] .Age]);

  FreeMemory (p);
{$ POINTERMATH OFF}
end ;