Mega Code Archive

 
Categories / Delphi / Activex OLE
 

How to get the html code for the parent of an activex form

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. uses ActiveX; { ... } FBrowser: IWebBrowser2; TYourActiveForm.YourMethod; var vClientSite: IOLEClientSite; {ActiveX} vContainer: IOLEContainer; {ActiveX} vServiceProvider: IServiceProvider; {ActiveX} vDocument: IHTMLDocument2; {MSHTML_TLB} vBackgroundImage: OleVariant; begin vClientSite := ActiveFormControl.ClientSite; vClientSite.GetContainer(vContainer); if vContainer.QueryInterface(IServiceProvider, vServiceProvider) = S_OK then begin if vServiceProvider.QueryService(IID_IWebBrowserApp, IID_IWebBrowser2, FBrowser) = S_OK then begin vDocument := FBrowser.Document as IHTMLDocument2; vBackgroundImage := vDocument.body.style.backgroundImage; if vBackgroundImage = '' then vBackgroundImage := vDocument.body.getAttribute('background', 0); if vBackgroundImge <> '' then ShowMessage(vBackgroundImage) else ShowMessage('No background image defined.'); end; end; end;