0

the following procedure works with Windows XP, 7-32, 7-64, 8-32, 8-64, with version of IE 8 to 11 more not work fot the new Windows 10, see the code:

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 is a string that contains the HTML "<html>...</html>"

also I tried to write the IHTMLDocument2 this way, but there was the same mistake:

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

Also I checked if there is a mshtml.dll in windows 10, and there is.

kobik
  • 21,001
  • 4
  • 61
  • 121
Jason-X
  • 39
  • 2
  • 11

2 Answers2

1

I tried your two examples on Win10 64-bit using 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;

and

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

and both execute without raising any exception. So it seems the problem is specific to your system, and, if it is, this q should probably be closed.

Fwiw, The code below works fine too

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;

and correctly displays the minimal HTML document from Memo1.Text in WebBrowser1.

MartynA
  • 30,454
  • 4
  • 32
  • 73
  • I'm not using TWebBrowser and can not even use it, I get the html of a direct component "TIdHttp", the exception occurs on the line exactly where I write the html "IDOC" – Jason-X Aug 19 '15 at 11:54
  • So, when you do the write on a system where it does work, what happens? Does it show on the screen or what? – MartynA Aug 19 '15 at 12:14
  • Like I said, when trying to write in IHTMLDocument2, is the exception "EOleException / Unspecified error" and this only occurs in Windows 10, all other versions it works. I have no idea what it is. – Jason-X Aug 19 '15 at 12:43
  • I know what you said - I'm just telling you the result I got. I've updated my answer to confirm that neither of your examples produce an exception on my Win10 system. – MartynA Aug 19 '15 at 13:44
  • you are using some key specifies for browser emulation? "FEATURE_BROWSER_EMULATION" – Jason-X Aug 19 '15 at 14:43
  • Not that I know of This was just a vanilla Win7 64-bit (VMWare) VM, upgraded to Windows 10. – MartynA Aug 19 '15 at 14:48
0

I discovered the problem was just the key "FEATURE_BROWSER_EMULATION" as I registered to work with older versions of IE in windows 10 this error occurs, it was only delete the key "FEATURE_BROWSER_EMULATION" related to my application which began operating in windows 10 , what I'll do is check the version of Windows and only register the key in older versions, thanks to all for the tips, I could only find the problem through the comments.

the key I was recording: "Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION"

value: 4270841

Jason-X
  • 39
  • 2
  • 11