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 : pointer;
size : longint;
pb : ^BYTE;
Getmem( p, size );
pb := p;
(pb + number)^:=255;
use:
Code:
VAR size : longint;
p : PByteArray;
Getmem( p, size );
p[number] :=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 : longint;
p : pointer;
pb : ^Byte;
Getmem( p, size );
pb := p;
inc( pb, size div sizeof(pb^) );
while pb <> p do
begin
dec(pb);
...
end;
Bookmarks