Oder schlicht so:
Delphi-Quellcode:
uses
Winapi.Winsock;
function IPToCardinal(
const AIP:
string): Cardinal;
begin
Result := ntohl(inet_addr(PAnsiChar(AnsiString(AIP))));
end;
Alternativ, wenn es manuell passieren soll (ohne Fehlerbehandlung):
Delphi-Quellcode:
function IPToCardinal2(const AIP: string): Cardinal;
var
Value, Octet: Cardinal;
i, ShlValue: Integer;
begin
Result := 0;
Value := 0;
ShlValue := 24;
for i := 1 to Length(AIP) do
begin
if AIP[i] = '.' then
begin
Result := Result or (Value shl ShlValue);
Value := 0;
ShlValue := ShlValue - 8;
end
else
Value := Value * 10 + (Ord(AIP[i]) - Ord('0'));
end;
Result := Result or Value;
end;