Mega Code Archive

 
Categories / Delphi / Activex OLE
 

How do i retrieve properties from an html page

Implement IPersistPropertyBag The DAX class framework implements the standard binary persistence interfaces, which allows most ActiveX containers to save and restore the properties of an embedded DAX-implemented control. Internet Explorer adds a new method to specify properties, the PARAM tag in an OBJECT statement. Because this is a textual representation of properties rather than a binary representation, IE defined a new interface called IPersistPropertyBag, whose purpose is to loading properties from text. The DAX class framework does not implement this new interface on TActiveXControl, so if you want your ActiveX control to be able to read textual properties from an HTML container, you will need to implement the interface. About IPersistPropertyBag ------------------------- IPersistPropertyBag declares the usual persistence methods, listed below. The container calls InitNew when it wishes to create a new instance of the object, Load when it wishes to cause an instance to retrieve properties from a property bag, and Save when it wishes to copy the object's properties into a property bag for writing to an HTML page. function GetClassID(out classID: TCLSID): HResult; stdcall; function InitNew: HResult; stdcall; function Load(const pPropBag: IPropertyBag; const pErrorLog: IErrorLog): HResult; stdcall; function Save(const pPropBag: IPropertyBag; fClearDirty: BOOL; fSaveAllProperties: BOOL): HResult; stdcall; Implementing IPersistPropertyBag -------------------------------- GetClassID and InitNew will be automatically bound to existing method implementations from the other persistence interfaces. You will need to bind the Load and Save interface methods to new method implementations in our subclass. The implementations of these methods will copy the control's properties to the property bag, and vice versa. Because each of the other persistence interfaces defines parameter-incompatible Load and Save methods, I follow the DAX convention of prepending the interface name, renaming the methods PersistPropertyBagLoad and PersistPropertyBagSave. Example: This example is drawn from the PROPBAG example source code. [ed: this example has not yet been published, but there's enough in here to be helpful.] TButtonX = class(TActiveXControl, IButtonX, IPersistPropertyBag) ... // IPersistPropertyBag function IPersistPropertyBag.Load = PersistPropertyBagLoad; function IPersistPropertyBag.Save = PersistPropertyBagSave; function PersistPropertyBagLoad(const pPropBag: IPropertyBag; const pErrorLog: IErrorLog): HResult; stdcall; function PersistPropertyBagSave(const pPropBag: IPropertyBag; fClearDirty: BOOL; fSaveAllProperties: BOOL): HResult; stdcall; end; function TButtonX.PersistPropertyBagLoad(const pPropBag: IPropertyBag; const pErrorLog: IErrorLog): HResult; stdcall; var v: OleVariant; begin if pPropBag.read( 'Cancel', v, pErrorLog) = S_OK then FDelphiControl.Cancel := v; if pPropBag.read( 'Caption', v, pErrorLog) = S_OK then FDelphiControl.Caption := v; if pPropBag.read( 'Cursor', v, pErrorLog) = S_OK then FDelphiControl.Cursor := v; if pPropBag.read( 'Default', v, pErrorLog) = S_OK then FDelphiControl.default := v; if pPropBag.read( 'DragCursor', v, pErrorLog) = S_OK then FDelphiControl.DragCursor := v; if pPropBag.read( 'DragMode', v, pErrorLog) = S_OK then FDelphiControl.DragMode := v; if pPropBag.read( 'Enabled', v, pErrorLog) = S_OK then FDelphiControl.Enabled := v; // Note that the font is a compound property in Delphi, but that HTML pages // do not have compound properties, so we implement each part as a separate // property. if pPropBag.read( 'FontName', v, pErrorLog) = S_OK then FDelphiControl.Font.Name := v; if pPropBag.read( 'FontSize', v, pErrorLog) = S_OK then FDelphiControl.Font.Size := v; // we could add font special styles, too if pPropBag.read( 'Visible', v, pErrorLog) = S_OK then FDelphiControl.Visible := v; Result := S_OK; end; function TButtonX.PersistPropertyBagSave(const pPropBag: IPropertyBag; fClearDirty: BOOL; fSaveAllProperties: BOOL): HResult; stdcall; var v: OleVariant; begin v:= FDelphiControl.Cancel; pPropBag.write( 'Cancel', v); v:= FDelphiControl.Caption; pPropBag.write( 'Caption', v); v:= FDelphiControl.Cursor; pPropBag.write( 'Cursor', v); v:= FDelphiControl.default; pPropBag.write( 'Default', v); v:= FDelphiControl.DragCursor; pPropBag.write( 'DragCursor', v); v:= FDelphiControl.DragMode; pPropBag.write( 'DragMode', v); v:= FDelphiControl.Enabled; pPropBag.write( 'Enabled', v); v:= FDelphiControl.Font.Name; pPropBag.write( 'FontName', v); v:= FDelphiControl.Font.Size; pPropBag.write( 'FontSize', v); v:= FDelphiControl.Visible; pPropBag.write( 'Visible', v); Result := S_OK; end; Object Safety ------------- Finally, in order for your control to work acceptably in a secure environment, you will need to certify that it is "safe for scripting". A control that is "safe for scripting", will not cause adverse effects no matter what properties are set or methods are called on the object. Methods for certifying that your control are safe for scripting are described in the ActiveX SDK section entitled "Marking a control as safe". [ed: I'll write a FAQ on this, too. These topics are all intertwined...]