资料来源网上,如有异议请联系删除。
经过验证和修改。twebbrowser如果不设置,默认使用系统默认核心,一般是IE8。
由于IE8版本较低,在特殊情况下,浏览网页会发生异常错误,不兼容等。需要修改调研的默认IE版本,默认使用系统的最高IE版本
{增加Registry引用}
function GetIEVersionStr: string;
var
Reg:TRegistry;
begin
Result := '';
Reg := TRegistry.Create;
try
Reg.RootKey := HKEY_LOCAL_MACHINE;
if Reg.OpenKeyReadOnly('Software\Microsoft\Internet Explorer') then
begin
//IE版本,不同版本键值不同
if Reg.ValueExists('svcVersion') then
Result := Reg.ReadString('svcVersion')
else
if Reg.ValueExists('Version') then
Result := Reg.ReadString('Version');
end;
finally
Reg.Free;
end;
end;
function IsWin64: Boolean;
//判断是否为64为系统
var
Kernel32Handle:THandle;
IsWow64Process: function(Handle:THandle;var Res:BOOL):BOOL;stdcall;
GetNativeSystemInfo:procedure(var lpSystemInfo:TSystemInfo);stdcall;
isWoW64: Bool;
SystemInfo: TSystemInfo;
const
PROCESSOR_ARCHITECTURE_AMD64=9;
PROCESSOR_ARCHITECTURE_IA64=6;
begin
Kernel32Handle:=GetModuleHandle('KERNEL32.DLL');
if Kernel32Handle=0 then
Kernel32Handle:=LoadLibrary('KERNEL32.DLL');
if Kernel32Handle<>0 then
begin
IsWOW64Process:=GetProcAddress(Kernel32Handle,'IsWow64Process');
GetNativeSystemInfo:=GetProcAddress(Kernel32Handle,'GetNativeSystemInfo');
if Assigned(IsWow64Process) then
begin
IsWow64Process(GetCurrentProcess,isWoW64);
Result:=isWoW64 and Assigned(GetNativeSystemInfo);
if Result then
begin
GetNativeSystemInfo(SystemInfo);
Result:=(SystemInfo.wProcessorArchitecture=PROCESSOR_ARCHITECTURE_AMD64)or
(SystemInfo.wProcessorArchitecture=PROCESSOR_ARCHITECTURE_IA64);
end;
end
else
Result:=False;
end
else
Result:=False;
end;
function WriteAppNameToReg: Boolean;
var
reg:TRegistry;
sPath,sAppName:String;
Sver:string;
lenver:Integer;
begin
Result:=True;
reg:=TRegistry.Create;
try
reg.RootKey:=HKEY_LOCAL_MACHINE;
sPath:='SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION';
if isWin64 then
sPath:='SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION';
if reg.OpenKey(sPath,True) then
begin
sAppName:=ExtractFileName(Application.ExeName);
Sver:=GetIEVersionStr;
lenver:=StrToInt( Copy(Sver,1,Pos('.',Sver)-1) );
//获取IE大版本号
if lenver<=7 then
reg.WriteInteger(sAppName,7000)
else
if lenver=8 then
begin
reg.WriteInteger(sAppName,8000)
end
else
if lenver=9 then
begin
reg.WriteInteger(sAppName,9000)
end
else
if lenver=10 then
begin
reg.WriteInteger(sAppName,10000)
end
else
if lenver=11 then
begin
reg.WriteInteger(sAppName,11001)
end;
end;
reg.CloseKey;
finally
FreeAndNil(reg);
end;
end;
标签:begin,end,sAppName,delphi,Reg,Twebbrowser,Result,IE,reg From: https://www.cnblogs.com/tang-delphi/p/16801245.html