Hex2Int Function
Converts a Hexadecimal (string) into an Integer.

Unit
QESBPCSConvert

Declaration
Function Hex2Int(const S: string): Integer;

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

Parameters
the String to process

Category
String/Integer Conversion Routines

Implementation

function Hex2Int (const S: string): Integer;
var
     S2: string;
     L: Integer;
     Error: Integer;
begin
     S2 := StripChFromStr (S, WhiteSpaceSet);
     if (Length (S2) > 1) and (S2 [1] <> '$') then
          S2 := '$' + S2;
     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