Index* functions accept their first argument as “untyped const” which is a concept unique to Pascal but, if you know C++, can be thought as
const void& (non-existent in C++). In C++, &-references are disguised pointers that, when used as functions arguments, automatically take the address of the passed variable. In Pascal, dynamic arrays are physically pointers, so when passed into the “untyped const”, the address of this pointer variable is taken, not the address of the contents it points to.
Visited[0] is a way to dereference said pointer and pass contents it points to, but I’d recommend
Pointer(Visited)^ because
Visited[0] triggers a range check error on empty
Visited array. OTOH,
Visited[0] will work with a static array without modifications, so the choice is up to you.
Try this:
procedure F_untyped(const data);
begin
writeln('F_untyped got pointer @', HexStr(@data));
end;
var
a: array of byte;
begin
SetLength(a, 5);
writeln('Address of A is ', HexStr(@a));
writeln('A pointer value is ', HexStr(pointer(a)));
writeln('Address of A contents is ', HexStr(@a[0]));
writeln(LineEnding + 'Calling F_untyped(a)');
F_untyped(a);
writeln(LineEnding + 'Calling F_untyped(a[0])');
F_untyped(a[0]);
writeln(LineEnding + 'Calling F_untyped(pointer(a)^)');
F_untyped(pointer(a)^);
end.