加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

如何在Delphi中查找IHTMLDocument2是否等于IDispatch文档?

发布时间:2020-12-15 04:16:29 所属栏目:大数据 来源:网络整理
导读:我有一个带有iFrame的TEmbeddedWB( https://sourceforge.net/projects/embeddedwb/).我必须找出特定的HTML标签是否在iFrame内部.我的iFrame对象是IHTMLFrameBase2,而Tag是IHTMLElement.我知道iFrame.contentWindow.document(它是一个IHTMLDocument2)与Tag.do
我有一个带有iFrame的TEmbeddedWB( https://sourceforge.net/projects/embeddedwb/).我必须找出特定的HTML标签是否在iFrame内部.我的iFrame对象是IHTMLFrameBase2,而Tag是IHTMLElement.我知道iFrame.contentWindow.document(它是一个IHTMLDocument2)与Tag.document相同.但Tag.document是一个IDispatch对象,因此下面给出了一个false:
if iFrame.contentWindow.document = Tag.document then ShowMessage('In iFrame')
else ShowMessage('Not in iFrame');

我知道这两个对象是一样的,因为Watch List可以显示它们的内存地址:

但是我无法从代码中获取他们的地址.我尝试过的:

Addr(iFrame.contentWindow.document) // Gives variable required error
@iFrame.contentWindow.document      // Gives variable required error
Pointer(iFrame.contentWindow.document)  //Compiles,but gives wrong address
Format('%p',[iFrame.contentWindow.document]) //Compiles,but gives EConvertError

注意:如果我逐行运行监视列表显示的地址在每行代码后都会发生变化,无论代码是否影响WebBrowser.

解决方法

从 rules of COM:

It is required that any call to QueryInterface on any interface for a given object instance for the specific interface IUnknown must always return the same physical pointer value. This enables calling QueryInterface(IID_IUnknown,…) on any two interfaces and comparing the results to determine whether they point to the same instance of an object (the same COM object identity).

所以,问他们两个IUnknown接口,并进行比较.

var
  disp: IDispatch;
  doc: IHTMLDocument2;
....
if (disp as IUnknown) = (doc as IUnknown) then
  ....

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读