使用Rad Studio 2007在vcl.net应用程序中读取代理详细信息

时间:2008-12-09 23:12:17

标签: delphi proxy delphi-2007

如何从vcl.net应用程序(Rad Studio 2007)中读取代理详细信息(地址和端口)? 听说过InternetGetProxyInfo。但是没有找到任何地方的细节。

谢谢。

1 个答案:

答案 0 :(得分:1)

只是想一个主意。我从来没有找到其他方式:(

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;