关于TWebBrowser.Document强制转换为IHTMLDocument2的问题(100分)

  • 主题发起人 xiaofeng_cxy
  • 开始时间
X

xiaofeng_cxy

Unregistered / Unconfirmed
GUEST, unregistred user!
我的代码如下:
AssignFile(htmltxt,'html.htm');
Rewrite(htmltxt);
try
Writeln(htmltxt,frmDM.GetRecord(ID));
finally
CloseFile(htmltxt);
end;

//IE.Navigate(ExtractFilePath(Application.ExeName)+'html.htm');
ShowHtml(IE,frmDM.GetRecord(ID));

ShowHtml如下
procedure TfrmMain.ShowHtml(Browser:TWebBrowser;htmlstr:string);
var
vv:Variant;
html:IHTMLDocument2;
begin
vv:=VarArrayCreate([0,0],varVariant);
vv[0]:=htmlstr;
html:=Browser.Document as IHTMLDocument2;
//ShowMessage(htmlstr);
//html.write(PSafeArray(TVarData(vv).VArray)); //原来到这会提示异常,介                          是将这句屏敝以后还是在                          这会出现异常
//html.charset:='gb2312';
html.Close;

我的这段是照抄左轻候的大富翁离线浏览器上的,他的可以正常运行,我的就会出错,不知道为什么????


//IE.Navigate(ExtractFilePath(Application.ExeName)+'html.htm');
这个地方我是用了一个临时文件来存放html代码,然后用TWebBrowser.Navigate方法来直接读取文件显示的,
这样就能正常运行了,不过速度比较慢!!

我在线恭候!!
 
怎么没人回答我呢????
 
function GetWebBrowserText(IE: TWebBrowser): string;
var
Doc: IHtmlDocument2;
Body: IHtmlElement;
begin
try
Result := '';
Doc := IE.Document as IHtmlDocument2;
if Doc = nil then Exit;
Body := Doc.Body;

if Body = nil then Exit;
Result := Body.innerText;
except end;
end;
 
procedure TfrmMain.ShowHtml(Browser:TWebBrowser;htmlstr:string);
var
vv:Variant;
html:IHTMLDocument2;
begin
Browser.Navigate('About:Blank');//對IHTMLDocument初始化。不然就是AV.
//這句可以放在OnCreate中
vv:=VarArrayCreate([0,0],varVariant);
vv[0]:=htmlstr;
html:=Browser.Document as IHTMLDocument2;
//ShowMessage(htmlstr);
//html.write(PSafeArray(TVarData(vv).VArray)); //原来到这会提示异常,介                          是将这句屏敝以后还是在                          这会出现异常
//html.charset:='gb2312';
html.Close;
 
顶部