Quote Originally Posted by holybyte
(offtopic..)
Isn't newer Delphi supporting Pointer arithmetics ?? I know there are several tutorial for accessing a pixel in allocated mem for delphi3/4. They all use complicated pointer<->int conversion.

Code:
// freepascal code
VAR p     &#58; pointer;
       size &#58; longint;
       pb   &#58; ^BYTE;

Getmem&#40; p, size &#41;;
pb &#58;= p;
&#40;pb + number&#41;^&#58;=255;
use:
Code:
VAR size &#58; longint;
       p   &#58; PByteArray;

Getmem&#40; p, size &#41;;
p&#91;number&#93; &#58;=255;
Much nicer code.

As far as I know even Turbo Pascal supported pointer arithmetic.


This code will walk over a raw byte a raw byte array backwards using pointer arithmetic. Inc() & dec() increase & decrease the pointer by the sizeof what the pointer points to(in this case a byte)
Code:
VAR 
  size &#58; longint;
  p &#58; pointer;
  pb   &#58; ^Byte;

Getmem&#40; p, size &#41;;
pb &#58;= p;
inc&#40; pb, size div sizeof&#40;pb^&#41; &#41;;
while pb <> p do
  begin
  dec&#40;pb&#41;;
  ...
  end;