# Internet Connectivty and Resolve host

This HostResolve procedure runs on a thread separately, to not interrupt other working functions. I would like to ask here if this procedure is correctly written or not?

Any recommendations and improvements, if any one willing to help?

Procedure HostResolve();

const

var
IP:String;
IsConnected:Boolean;
i:integer;

begin

IsConnected := false;
While true do
begin
if IsConnectedToInternet then
begin
if IsConnected = false then
begin
//

for  i := Low(URL) to High(URL) do
begin
if  HostToIp(URL[i], IP) then
begin
ShowMessage(IP);
IsConnected := true;
Break;
end;
end;

//
end;
end else begin
IsConnected := false;
end;
Sleep(1000);
end;
end;

Function IsConnectedToInternet: Boolean;
var
dwConnectionTypes: DWORD;
begin
dwConnectionTypes :=
INTERNET_CONNECTION_MODEM +
INTERNET_CONNECTION_LAN +
INTERNET_CONNECTION_PROXY;
Result := InternetGetConnectedState(@dwConnectionTypes, 0);
end;

Function HostToIP(sHost: string; var sIP: string):Boolean;
var
aHostName: array[0..255] of Char;
HostEnt  : PHostEnt;
begin
WSAStartup(\$0101, wsData);
try
GetHostName(aHostName, SizeOf(aHostName));
StrPCopy(aHostName, sHost);
hostEnt := GetHostByName(aHostName);
if Assigned(HostEnt) then
Result := True;
end else
Result := False;
end else
Result := False
else begin
Result := False;
end;
finally
WSACleanup;
end;
end;

• @Greenonline do not edit code unless you are sure this is due to copy and paste errors. – Pimgd Feb 19 '15 at 8:12
• Ok, sorry. I was just trying to indent so as to make the code a bit more readable. The _begin_s and _end_s didn't line up correctly, and made it a bit hard to read. As were the blank lines. I hoped that it would help someone to provide an answer. :-) – Greenonline Feb 19 '15 at 8:15