How can I check whether a string contains a valid IP (IPv4) address?

The simplest way is to use the Windows inet_addr function, which is part of the Windows Socket 2 implementation, as in this example:

function IsValidIPv4Address(AAddress: String): Boolean;
begin
  Result:=inet_addr(PChar(AAddress))<>INADDR_NONE;
end;

Source: www.guidogybels.net.