Author: Tomas Rutkauskas
Does anyone know how to get the HTML code for the parent of an ActiveX form? The
problem we have is an ActiveX Form which is loaded into a HTML document. This
ActiveX form has buttons on it to load additional ActiveX forms. We want to place
these additional ActiveX forms onto the current HTML page into a frame.
Answer:
The code below shows you how to grab the document, etc., from an ActiveForm.
1 uses2 ActiveX;
3 4 { ... }5 6 FBrowser: IWebBrowser2;
7 8 TYourActiveForm.YourMethod;
9 var10 vClientSite: IOLEClientSite; {ActiveX}11 vContainer: IOLEContainer; {ActiveX}12 vServiceProvider: IServiceProvider; {ActiveX}13 vDocument: IHTMLDocument2; {MSHTML_TLB}14 vBackgroundImage: OleVariant;
15 begin16 vClientSite := ActiveFormControl.ClientSite;
17 vClientSite.GetContainer(vContainer);
18 if vContainer.QueryInterface(IServiceProvider, vServiceProvider) = S_OK then19 begin20 if vServiceProvider.QueryService(IID_IWebBrowserApp, IID_IWebBrowser2,
21 FBrowser) = S_OK then22 begin23 vDocument := FBrowser.Document as IHTMLDocument2;
24 vBackgroundImage := vDocument.body.style.backgroundImage;
25 if vBackgroundImage = '' then26 vBackgroundImage := vDocument.body.getAttribute('background', 0);
27 if vBackgroundImge <> '' then28 ShowMessage(vBackgroundImage)
29 else30 ShowMessage('No background image defined.');
31 end;
32 end;
33 end;