1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| function IsNetWorkActivatedTried: boolean; var WinHttpReq: Variant; Connected: Boolean; iTriedTime: Integer; begin Connected := False; iTriedTime := 0; repeat iTriedTime := iTriedTime + 1; Log('Checking connection to the server, try ' + + IntToStr(iTriedTime) + ' time.'); try
WinHttpReq := CreateOleObject('WinHttp.WinHttpRequest.5.1'); WinHttpReq.SetTimeouts('3000', '3000', '3000', '3000'); // Use your real server host name WinHttpReq.Open('GET', 'https://www.goolge.de/', False); WinHttpReq.Send(''); Log('Connected to the server; status: ' + IntToStr(WinHttpReq.Status) + ' ' + WinHttpReq.StatusText); Connected := True; except Log('Error connecting to the server, msg: ' + GetExceptionMessage + 'try again! '); end; until (iTriedTime = 3) or (Connected = True) ; Result := Connected; end;
|