Delphi val( '$ffffffffffffffff', intVar, code)
just behaves like overloaded functions:
1) If intVar has type int64, then intVar becomes -1,
because val() implements implicit typecast from uint64 input to int64.
2) If intVar has type uint64, then intVar becomes high(uint64).
3) Both get (code = 0).
It's like in Delphi assignment:
i64 := -$1; // fully compatible
i64 := $ffffffffffffffff; // implicit cast with out-of-range warning, but -1 still is assigned
u64 := $ffffffffffffffff; // fully compatible
I mentioned the Delphi implicit typecast in:
https://forum.lazarus.freepascal.org/index.php/topic,50968.0.html