[pascal]
function getPtrLength(_ptr : PBYTE) : integer;
begin
Result := 0;
repeat
inc(Result);
inc(_ptr);
until _ptr^ = 0;

//i believe repeat will be better as the cmp instruction should be placed at the end of the loop rather than to waste 1 extra jmp instruction.
end;


var
ptr , _start : PByte;
begin
getmem(ptr,101); //1 end byte
_start := ptr;
for i := 1 to 100 do
begin
ptr^ := Random(100); // fill our array with random numbers
inc(ptr);
end;
ptr^ := 0;
//use our function here
ShowMessage(IntToStr(getPtrLength(_start))); // expected result is 100 !! but its is
end.
[/pascal]