这里的另一种方法,我用的,它并不需要直接注册表访问。这在D2007下工作,但我不明白为什么它不能在D7下工作。
uses
WinInet,
SysUtils;
function UseIEProxyInfo(var ProxyHost: String; var ProxyPort: Integer): Boolean;
var
ProxyInfo: PInternetProxyInfo;
Len: LongWord;
ProxyDetails: String;
s2: String;
i1: Integer;
procedure RemoveProtocol(var str: string);
var
i1 : integer;
begin
i1 := PosText('://', str);
if i1 > 0 then
Delete(str, 1, i1 + 2);
i1 := PosText('http=', str);
if i1 > 0 then begin
Delete(str, 1, i1 + 4);
str := SubStr(str, 1, ' ');
end;
end;
begin
Result := False;
Len := 4096;
GetMem(ProxyInfo, Len);
try
if InternetQueryOption(nil, INTERNET_OPTION_PROXY, ProxyInfo, Len) then
begin
if ProxyInfo^.dwAccessType = INTERNET_OPEN_TYPE_PROXY then
begin
Result := True;
ProxyDetails := ProxyInfo^.lpszProxy;
RemoveProtocol(ProxyDetails);
s2 := SubStr(ProxyDetails, 2, ':');
if s2 <> '' then
begin
try
i1 := StrToInt(s2);
except
i1 := -1;
end;
if i1 <> -1 then
begin
ProxyHost := SubStr(ProxyDetails, 1, ':');
ProxyPort := i1;
end;
end;
end;
end;
finally
FreeMem(ProxyInfo);
end;
end;
+1,但如果我没有记错,那是只有IE,虽然。 Firefox和其他浏览器维护自己的代理设置。 – 2010-01-06 15:12:05
这是真的,但我认为如果OP想要通过系统调用获得它,那么他就是这么做的。 – 2010-01-06 15:28:52
谢谢!现在我知道要搜索什么,我在这里找到了一些代码:http://coding.derkeiler.com/Archive/Delphi/borland.public.delphi.nativeapi/2004-01/0205.html – devstopfix 2010-01-12 20:41:18