Code:
function getPtrLength(_ptr : PBYTE) : integer;
begin
Result := 0;
while ( _ptr <> NIL ) do
begin
inc(Result);
inc(_ptr);
end;
end;
why this function cause a loop for ever when passed an array of byte
when use it like this
Code:
var
ptr , _start : PByte;
begin
getmem(ptr,100);
_start := ptr;
for i := 1 to 100 do
begin
ptr^ := Random(100); // fill our array with random numbers
inc(ptr);
end;
//use our function here
ShowMessage(inttostr(getPtrLength(_start))); // expected result is 100 !! but its not
end.
whats wrong here , thanks
Bookmarks