How to determine if an IHTMLDocument2 document matches an IDispatch document in Delphi?

I have a TEmbeddedWB ( https://sourceforge.net/projects/embeddedwb/ ) with an iFrame in it. I have to find out if a certain HTML tag is inside the iFrame or not. My iFrame is an IHTMLFrameBase2 object and the tag is IHTMLElement . I know that iFrame.contentWindow.document (which is IHTMLDocument2 ) is the same as Tag.document . But Tag.document is an IDispatch object, so the following gives false:

 if iFrame.contentWindow.document = Tag.document then ShowMessage('In iFrame') else ShowMessage('Not in iFrame'); 

I know that both objects are the same because the watchlist can display its memory address:

Watch List

But I can not get their addresses from the code. What I tried:

 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 

Note. If I run line by line, the addresses displayed in the watchlist change after each line of code, whether the code affects WebBrowser or not.

+7
delphi iframe
source share
1 answer

From COM rules :

It is required that any call to QueryInterface on any interface for an instance of a given object for a particular interface IUnknown always return the same value of the physical pointer. This allows you to call QueryInterface (IID_IUnknown, ...) on any two interfaces and compare the results to determine whether they point to the same instance of the object (the same COM object identifier).

So, ask them both for the IUnknown interface and compare.

 var disp: IDispatch; doc: IHTMLDocument2; .... if (disp as IUnknown) = (doc as IUnknown) then .... 
+10
source share

All Articles