Hex2Int64 Function
Converts a Hexadecimal (string) into a LongWord.

Unit
QESBPCSConvert

Declaration
Function Hex2Int64(const S: string): Int64;

Description
Removes any leading or trailing white spaces (ie <= #32). Initial '$' not required but acceptable. Non-hexadecimal will return 0.

Parameters
the String to process

Category
String/Integer Conversion Routines

Implementation

function Hex2Int64 (const S: string): Int64;
var
     S2: string;
     L: Int64;
     Error: Integer;
begin
     S2 := UpperCase (StripChFromStr (S, WhiteSpaceSet));
     if (Length (S2) > 1) and (S2 [1] <> '$') then
          S2 := '$' + S2;

     { Some Delphi/Kylix versions have problems with the following so we
      handle them as special cases. }

     if S2 = '$FFFFFFFFFFFFFFFF' then
     begin
          Result := -1;
          Exit;
     end;

     if S2 = '$8000000000000000' then
     begin
          Result := Low (Int64);
          Exit;
     end;

     try
          Val (S2, L, Error);
          if Error <> 0 then
               Result := 0 // Return 0 for non-numeric
          else
               Result := L; // Return Value
     except
          Result := 0; // Return 0 for non-numeric
     end;
End;


HTML generated by Time2HELP
http://www.time2help.com