如何判断 IHTMLDocument2为空

xionw 2008-03-30 03:43:12
if Assigned(wb1) then
///保证网页里有内容;即已经打开一个网页!
begin
try
hdoc:=wb1.document as ihtmldocument2;
if Assigned(HDoc) then
//如果不为空
begin
mywbstr:=hdoc.body.outerText;
end;
except
Exit;
end;
end;
我想做的事如果不为空就输出到字串mywbstr中,但是现在不知道为什么为空的时候也继续操作输出那一部,完全就会
出现内存错误,请知道的朋友指点一下为什么前面的判断会失败呢?怎么才能可靠的判断hdoc为空呢?
...全文
53 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
hongqi162 2008-03-31
  • 打赏
  • 举报
回复
procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
var
CurWebrowser: IWebBrowser;
TopWebBrowser: IWebBrowser;
Document: OleVariant;
WindowName: string;
begin
CurWebrowser := pDisp as IWebBrowser;
TopWebBrowser:= (Sender as TWebBrowser).DefaultInterface;
if CurWebrowser = TopWebBrowser then
begin
Document:=CurWebrowser.Document;
showmessage( Document.body.outerText );
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
WebBrowser1.Navigate('www.google.com');
end;
hongqi162 2008-03-31
  • 打赏
  • 举报
回复
在WebBrowser执行Navigate后你可以在WebBrowser的OnDocumentComplete判断执行情况,以及取某些值
xionw 2008-03-30
  • 打赏
  • 举报
回复
顶个。。请朋友们进来哈

1,593

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 网络通信/分布式开发
社区管理员
  • 网络通信/分布式开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧