IPStr2LWord Function
Converts a String representing an IP Address 'xxx.xxx.xxx.xxx' into the equivalent LongWord.

Unit
QESBPCSConvert

Declaration
Function IPStr2LWord(const IPAddr: string): LongWord;

Description
If ESBRaiseIPError is true then an Exception is raised if a IP Address Conversion error occurs, if false just returns 0.

Parameters
IPAddr String representing an IP Address.

Category
String/Integer Conversion Routines

Implementation

function IPStr2LWord (const IPAddr: string): LongWord;
var
     I, P: Integer;
     S: string;
     X: Longword;
begin
     Result := 0;
     S := IPAddr;
     for I := 1 to 4 do
     begin
          P := ESBPosCh ('.', S);
          if P > 0 then
          begin
               X := Str2LWord (LeftStr (S, P - 1));
               S := RightAfterStr (S, P);
          end
          else
          begin
               X := Str2LWord (S);
               S := '';
          end;

          if (X > 255) then
          begin
               Result := 0;
               if ESBRaiseIPError then
                    raise EMathError.Create (rsIPAddrComp)
          end
          else
               Result := Result * Int64 (256) + X;
     end;
End;


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