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

Unit
QESBPCSConvert

Declaration
Function Hex2LWord(const S: string): LongWord;

Description
Removes any leading or trailing white spaces (ie <= #32). Initial '$' not required but acceptable. If Number is Valid but out of Range then High (LongWord) will be returned for a greater value and 0 for a lesser value. Non-hexadecimal will return 0.

Parameters
the String to process

Category
String/Integer Conversion Routines

Implementation

function Hex2LWord (const S: string): LongWord;
var
     S2: string;
     L: Int64;
     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 if L > High (LongWord) then // Check with in boundaries
               Result := High (LongWord)
          else if L < Low (LongWord) then
               Result := Low (LongWord)
          else
               Result := L; // Return Value
     except
          Result := 0; // Return 0 for non-numeric
     end;
End;


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