我在国外网站也查过相关问题,结果是:无法立即生效。
具体的修改方法如下:
首先将下面的文件保存为WininetAppend.pas,是我改写了
C++Builder关于IE5的一些东西,Delphi5中没有这些。
unit WininetAppend;
interface
uses
Windows;
type
PInternetPerConnOption = ^INTERNET_PER_CONN_OPTION;
INTERNET_PER_CONN_OPTION = record
dwOption: DWORD;
case Integer of
0: (dwValue: DWORD);
1: (pszValue:LPTSTR);
2: (ftValue: FILETIME);
end;
PInternetPerConnOptionList = ^INTERNET_PER_CONN_OPTION_LIST;
INTERNET_PER_CONN_OPTION_LIST = record
dwSize
WORD;
pszConnection :LPTSTR;
dwOptionCount
WORD;
dwOptionError
WORD;
pOptions
InternetPerConnOption;
end;
//
// Options used in INTERNET_PER_CONN_OPTON struct
//
const
INTERNET_PER_CONN_FLAGS = 1;
INTERNET_PER_CONN_PROXY_SERVER = 2;
INTERNET_PER_CONN_PROXY_BYPASS = 3;
INTERNET_PER_CONN_AUTOCONFIG_URL = 4;
INTERNET_PER_CONN_AUTODISCOVERY_FLAGS = 5;
//
// PER_CONN_FLAGS
//
PROXY_TYPE_DIRECT = $00000001; // direct to net
PROXY_TYPE_PROXY = $00000002; // via named proxy
PROXY_TYPE_AUTO_PROXY_URL = $00000004; // autoproxy URL
PROXY_TYPE_AUTO_DETECT = $00000008; // use autoproxy detection
//
// PER_CONN_AUTODISCOVERY_FLAGS
//
AUTO_PROXY_FLAG_USER_SET = $00000001; // user changed this setting
AUTO_PROXY_FLAG_ALWAYS_DETECT = $00000002; // force detection even when its not needed
AUTO_PROXY_FLAG_DETECTION_RUN = $00000004; // detection has been run
AUTO_PROXY_FLAG_MIGRATED = $00000008; // migration has just been done
AUTO_PROXY_FLAG_DONT_CACHE_PROXY_RESULT = $00000010; // don't cache result of host=proxy name
AUTO_PROXY_FLAG_CACHE_INIT_RUN = $00000020; // don't initalize and run unless URL expired
AUTO_PROXY_FLAG_DETECTION_SUSPECT = $00000040; // if we're on a LAN & Modem, with only one IP, bad?!?
INTERNET_OPTION_PER_CONNECTION_OPTION = 75;
implementation
end.
主程序中:
uses
Wininet, WininetAppend;
function TfrmMain.GetProxyInfo(var AutoDetect,AutoProxyUrl,
DirectConnect,ProxyConnect:boolean;var AutoProxyUrlAddress,
ByPassAddress,ProxyServer:String):boolean;
var
nSize : DWORD;
List : INTERNET_PER_CONN_OPTION_LIST;
Option: array[0..3] of INTERNET_PER_CONN_OPTION;
begin
nSize := sizeof(INTERNET_PER_CONN_OPTION_LIST);
Option[0].dwOption := INTERNET_PER_CONN_AUTOCONFIG_URL;
Option[1].dwOption := INTERNET_PER_CONN_FLAGS;
Option[2].dwOption := INTERNET_PER_CONN_PROXY_BYPASS;
Option[3].dwOption := INTERNET_PER_CONN_PROXY_SERVER;
List.dwSize := sizeof(INTERNET_PER_CONN_OPTION_LIST);
List.pszConnection := nil;
List.dwOptionCount := 4;
List.dwOptionError := 0;
List.pOptions := @Option;
result := InternetQueryOption(nil, INTERNET_OPTION_PER_CONNECTION_OPTION, @List, nSize);
if not result then exit;
if(Option[0].pszValue <> nil) then
begin
AutoProxyUrlAddress := StrPas(Option[0].pszValue);
GlobalFreePtr(Option[0].pszValue);
end
else
AutoProxyUrlAddress := '';
DirectConnect := (Option[1].dwValue and PROXY_TYPE_DIRECT ) = PROXY_TYPE_DIRECT;
ProxyConnect := (Option[1].dwValue and PROXY_TYPE_PROXY ) = PROXY_TYPE_PROXY;
AutoProxyUrl := (Option[1].dwValue and PROXY_TYPE_AUTO_PROXY_URL) = PROXY_TYPE_AUTO_PROXY_URL;
AutoDetect := (Option[1].dwValue and PROXY_TYPE_AUTO_DETECT) = PROXY_TYPE_AUTO_DETECT;
if(Option[2].pszValue <> nil) then
begin
ByPassAddress := StrPas(Option[2].pszValue);
GlobalFreePtr(Option[2].pszValue);
end
else
ByPassAddress := '';
if(Option[3].pszValue <> nil) then
begin
ProxyServer := StrPas(Option[3].pszValue);
GlobalFreePtr(Option[3].pszValue);
end
else
ProxyServer := '';
end;
function TfrmMain.SetProxyInfo(const ProxyConnect:boolean;const ByPassAddress,ProxyServer:String):boolean;
var
nSize : DWORD;
List : INTERNET_PER_CONN_OPTION_LIST;
Option: array[0..2] of INTERNET_PER_CONN_OPTION;
begin
nSize := sizeof(INTERNET_PER_CONN_OPTION_LIST);
Option[0].dwOption := INTERNET_PER_CONN_FLAGS;
if ProxyConnect then
Option[0].dwValue := PROXY_TYPE_PROXY
else
Option[0].dwValue := PROXY_TYPE_DIRECT;
Option[1].dwOption := INTERNET_PER_CONN_PROXY_BYPASS;
Option[1].pszValue := PChar(ByPassAddress);
Option[2].dwOption := INTERNET_PER_CONN_PROXY_SERVER;
Option[2].pszValue := PChar(ProxyServer);
List.dwSize := sizeof(INTERNET_PER_CONN_OPTION_LIST);
List.pszConnection := nil;
List.dwOptionCount := 3;
List.dwOptionError := 0;
List.pOptions := @Option;
result := InternetSetOption(nil, INTERNET_OPTION_PER_CONNECTION_OPTION, @List, nSize);
end;
//ProxyServer格式: 127.0.0.1:8080