title: Decrease InternetOpenUrl timeout?
body: <p>This function checks whether an URL can be reached or not:</p>
  
  <pre><code>uses wininet, System.Types,
  
  ...
  
  function CheckUrl(url: string): boolean;
  var
    hSession, hfile, hRequest: hInternet;
    dwindex, dwcodelen: dword;
    dwcode: array [1 .. 20] of char;
    res: pchar;
  begin
    if pos('http://', lowercase(url)) = 0 then
      url := 'http://' + url;
    Result := false;
    hSession := InternetOpen('InetURL:/1.0', INTERNET_OPEN_TYPE_PRECONFIG,
      nil, nil, 0);
    if assigned(hSession) then
    begin
      hfile := InternetOpenUrl(hSession, pchar(url), nil, 0,
        INTERNET_FLAG_RELOAD, 0);
      dwindex := 0;
      dwcodelen := 10;
      HttpQueryInfo(hfile, HTTP_QUERY_STATUS_CODE, @dwcode, dwcodelen, dwindex);
      res := pchar(@dwcode);
      Result := (res = '200') or (res = '302');
      if assigned(hfile) then
        InternetCloseHandle(hfile);
      InternetCloseHandle(hSession);
    end;
  end;
  </code></pre>
  
  <p>However, when there is no Internet connection, the function returns only after 21 seconds. So how can I restrict the timeout to 2 seconds?</p>
  
  <p>Here is a test program:</p>
  
  <pre><code>program CheckURLTest;
  
  {.$APPTYPE CONSOLE}
  {.$R *.res}
  
  uses
    CodeSiteLogging,
    wininet,
    System.Types,
    System.SysUtils;
  
  function CheckUrl(url: string): boolean;
  var
    hSession, hfile, hRequest: hInternet;
    dwindex, dwcodelen: dword;
    dwcode: array [1 .. 20] of char;
    res: pchar;
  begin
    if pos('http://', lowercase(url)) = 0 then
      url := 'http://' + url;
    Result := false;
    hSession := InternetOpen('InetURL:/1.0', INTERNET_OPEN_TYPE_PRECONFIG,
      nil, nil, 0);
    if assigned(hSession) then
    begin
      hfile := InternetOpenUrl(hSession, pchar(url), nil, 0,
        INTERNET_FLAG_RELOAD, 0);
      dwindex := 0;
      dwcodelen := 10;
      HttpQueryInfo(hfile, HTTP_QUERY_STATUS_CODE, @dwcode, dwcodelen, dwindex);
      res := pchar(@dwcode);
      Result := (res = '200') or (res = '302');
      if assigned(hfile) then
        InternetCloseHandle(hfile);
      InternetCloseHandle(hSession);
    end;
  end;
  
  var
    TestURL: string;
  
  begin
    try
      TestURL := 'http://www.google.com';
  
      CodeSite.Send('VOR CheckUrl');
      if CheckUrl(TestURL) then
        CodeSite.Send(TestURL + ' exists!')
      else
        CodeSite.Send(TestURL + ' does NOT exist!');
  
    except
      on E: Exception do
        Writeln(E.ClassName, ': ', E.Message);
    end;
  
  end.
  </code></pre>