以下过程适用于Windows XP、7-32、7-64、8-32、8-64,IE 8到11的更多版本不适用于新的Windows 10,请参阅代码:
try
IDoc := CreateComObject(Class_HTMLDOcument) as IHTMLDocument2;
IDoc.Write(PSafeArray(VarArrayAsPSafeArray(VarArrayOf([xHtml])))); //Error windows 10
IDoc.Close;
except
on E: Exception do
begin
//E.ClassName = EOleException
//E.Message = Unspecified error
end;
end;xHtml是包含超文本标记语言"<html>...</html>"的字符串
我也试着这样写IHTMLDocument2,但还是犯了同样的错误:
IDoc := CreateComObject(Class_HTMLDOcument) as IHTMLDocument2;
v := VarArrayCreate([0, 0], VarVariant);
v[0] := xHtml;
IDoc.Write(PSafeArray(TVarData(v).VArray));
IDoc.Close;我还检查了Windows10中是否有mshtml.dll,确实有。
发布于 2015-08-19 16:12:12
我使用XE8在64位Win10上测试了您的两个示例。
try
IDoc := CreateComObject(Class_HTMLDOcument) as IHTMLDocument2;
IDoc.Write(PSafeArray(VarArrayAsPSafeArray(VarArrayOf([xHtml])))); //Error windows 10
IDoc.Close;
except
on E: Exception do
begin
//E.ClassName = EOleException
//E.Message = Unspecified error
end;
end;和
IDoc := CreateComObject(Class_HTMLDOcument) as IHTMLDocument2;
v := VarArrayCreate([0, 0], VarVariant);
v[0] := xHtml;
IDoc.Write(PSafeArray(TVarData(v).VArray));
IDoc.Close;并且执行时都不会引发任何异常。因此,问题似乎是特定于您的系统的,如果是这样,这个Q可能应该关闭。
Fwiw,下面的代码也运行得很好
procedure LoadWBFromString(WB : TWebBrowser; const S : String);
var
Doc : IHtmlDocument2;
V : OleVariant;
begin
if WB.Document = nil then
WB.Navigate('about:blank');
Doc := WB.Document as IHTMLDocument2;
V := VarArrayCreate([0, 0], varVariant);
V[0] := S;
Doc.Write(PSafeArray(TVarData(v).VArray));
Doc.Close;
end;
procedure TForm1.LoadWB;
begin
LoadWBFromString(WebBrowser1, Memo1.Lines.Text);
end;并在WebBrowser1中正确显示Memo1.Text中的最小超文本标记语言文档。
发布于 2015-08-19 23:21:17
当我在Windows10中注册使用旧版本的IE时,我发现问题只是键"FEATURE_BROWSER_EMULATION“这个错误发生了,它只是删除了与我的应用程序相关的键"FEATURE_BROWSER_EMULATION”,它开始在Windows10中运行,我要做的是检查windows的版本,只在旧版本中注册该键,感谢所有的提示,我只能通过评论发现问题。
我录制的密钥是:“软件\微软\互联网Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION”
取值: 4270841
https://stackoverflow.com/questions/32085249
复制相似问题