2015-08-19 42 views
0

以下過程適用於Windows XP,7-32,7-64,8-32,8-64,其中IE 8至11的版本更多不適用於新的的Windows 10,看到代碼:在IHTMLDocument2.write中的EOleException僅在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這種方式,但有同樣的錯誤的HTML的字符串:

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

另外我檢查了在Windows 10中是否有​​,並且有。

+0

你說的 「不工作」 是什麼意思? – kobik

+0

我的意思是在10個寡婦中,發生錯誤,而不是。 –

+0

什麼是'xHtml'?這是一個字符串嗎? – kobik

回答

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; 

並正確顯示從Memo1.Text在WebBrowser1最小的HTML文檔。

+0

我沒有使用TWebBrowser並且甚至不能使用它,我得到了直接組件「TIdHttp」的html,該行發生異常確切地說我在那裏寫html「IDOC」 –

+0

所以,當你在一個系統上寫文件時,會發生什麼?它顯示在屏幕上還是什麼? – MartynA

+0

就像我說的,當試圖在IHTMLDocument2中編寫時,是「EOleException/Unspecified error」的異常,並且這隻發生在Windows 10中,它的所有其他版本都適用。我不知道它是什麼。 –

0

我發現了這個問題,只是關鍵「FEATURE_BROWSER_EMULATION」爲我註冊與Windows 10出現此錯誤,它只是刪除鍵「FEATURE_BROWSER_EMULATION」與我的應用程序,它開始在Windows操作系統老版本的IE瀏覽器的工作10,我要做的是檢查Windows的版本,只註冊舊版本的密鑰,感謝所有提示,我只能通過評論找到問題。

我記錄的關鍵: 「軟件\微軟\的Internet Explorer \ MAIN \ FeatureControl \ FEATURE_BROWSER_EMULATION」

值:4270841