我有一个带有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 ....