我有一个带有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可以显示它们的内存地址:
解决方法
从
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
- ....