如何从vcl.net应用程序(Rad Studio 2007)中读取代理详细信息(地址和端口)?
听说过InternetGetProxyInfo。但没有找到任何地方的细节。
谢谢。
最佳答案
只是给一个想法。我再也找不到其他方法了:(
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;