views:

86

answers:

1

How to read the proxy details (address and port) from a vcl.net application (Rad Studio 2007) ?. Heard about InternetGetProxyInfo. But didnt find the details any where.

Thank you.

A: 

Just to give an idea. I never find other way :(

procedure TfrmProxy.sbtnGetIEProxyClick(Sender: TObject);

  function GetHTTPProxy(const str: String): String;
  var
    ts: TStringList;
    i: Integer;
  begin
    ts := TStringList.Create;
    try
      ts.Text := StringReplace(str, ';', #13#10, [rfReplaceAll]);
      if ts.Count = 1 then
        Result := ts[0]
      else
      begin
        for i := 0 to ts.Count-1 do
        begin
          if pos(UpperCase('http'), uppercase(ts[i])) > 0 then
          begin
            Result := Copy(ts[i], 6, length(ts[i]));
            Exit;
          end;
        end;
      end;
    finally
      ts.Free;
    end;
  end;


var
  Reg: TRegistry;
  str: String;
begin
  Reg := TRegistry.Create;
  try
    Reg.RootKey := HKEY_CURRENT_USER;
    if Reg.KeyExists('Software\Microsoft\Windows\CurrentVersion\Internet Settings') then
    begin
      Reg.OpenKeyReadOnly('Software\Microsoft\Windows\CurrentVersion\Internet Settings');
      chxUseProxy.Checked := Reg.ReadInteger('ProxyEnable') <> 0;
      if chxUseProxy.Checked then
      begin
        str := Reg.ReadString('ProxyServer');
        str := GetHTTPProxy(str);
        ledtProxyHost.Text := Copy(str, 0, pos(':', str)-1);
        ledtProxyPort.Text := Copy(str, pos(':', str)+1, length(str));
      end;
      Reg.CloseKey;
    end;
  finally
    Reg.Free;
  end;
end;
Hugues Van Landeghem