【问题标题】:EOleException in IHTMLDocument2.write only in the windows 10IHTMLDocument2.write 中的 EOleException 仅在 windows 10 中
【发布时间】:2015-08-19 01:46:28
【问题描述】:

以下程序适用于 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>...</html>" 的字符串

我也尝试用这种方式编写 IHTMLDocument2,但出现了同样的错误:

IDoc := CreateComObject(Class_HTMLDOcument) as IHTMLDocument2;
v := VarArrayCreate([0, 0], VarVariant);
v[0] := xHtml;
IDoc.Write(PSafeArray(TVarData(v).VArray));
IDoc.Close;

我还检查了 Windows 10 中是否有 mshtml.dll,并且有。

【问题讨论】:

  • “不工作”是什么意思?
  • 我的意思是在10个寡妇中,错误发生,并没有。
  • 什么是xHtml?是字符串吗?
  • 是的,xHtml 是一个包含 html "..." 的字符串

标签: delphi windows-10 ihtmldocument2


【解决方案1】:

我在 Win10 64 位上使用 XE8 尝试了你的两个示例。

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 的最小 HTML 文档。

【讨论】:

  • 我没有使用TWebBrowser,甚至不能使用它,我得到了一个直接组件“TIdHttp”的html,异常发生在我写html“IDOC”的那一行跨度>
  • 那么,当你在一个可以工作的系统上进行写入时,会发生什么?它是显示在屏幕上还是什么?
  • 就像我说的,当尝试在 IHTMLDocument2 中写入时,出现异常“EOleException / Unspecified error”,这只发生在 Windows 10 中,所有其他版本都有效。我不知道它是什么。
  • 我知道你在说什么——我只是告诉你我得到的结果。我已经更新了我的答案,以确认您的两个示例都不会在我的 Win10 系统上产生异常。
  • 您正在使用某些键指定用于浏览器仿真? “FEATURE_BROWSER_EMULATION”
【解决方案2】:

我发现问题只是键“FEATURE_BROWSER_EMULATION”,因为我在 Windows 10 中注册了使用旧版本的 IE ,我现在就是检查一下windows的版本,只注册老版本的key,感谢大家的提示,我只能通过cmets找到问题了。

我记录的密钥:“Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION”

值:4270841

【讨论】:

    猜你喜欢
    • 2010-10-18
    • 2017-07-18
    • 1970-01-01
    • 2019-04-02
    • 1970-01-01
    • 2019-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多