這裏的另一種方法,我用的,它並不需要直接註冊表訪問。這在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