You are right: Val() not compatible with UInt64 / QWord .
There are two overloaded functions:
- One returns a floating point value;
Int64 returned (i.e. the signed value).
You can use this code instead:
function StrToUInt64(const S: String): UInt64; var c: cardinal; P: PChar; begin P := Pointer(S); if P=nil then begin result := 0; exit; end; if ord(P^) in [1..32] then repeat inc(P) until not(ord(P^) in [1..32]); c := ord(P^)-48; if c>9 then result := 0 else begin result := c; inc(P); repeat c := ord(P^)-48; if c>9 then break else result := result*10+c; inc(P); until false; end; end;
It will work in both Unicode and Unicode versions of Delphi.
On error, 0 is returned.
Arnaud bouchez
source share