Mega Code Archive

 
Categories / Delphi / Activex OLE
 

How do I know if my ActiveX control is in design or run mode

Title: How do I know if my ActiveX control is in design or run mode? Question: You can find out by determining if your control's container is in design mode. You can find this out by querying the container's UserMode ambient property. Answer: Example: // This function returns a pointer to a contained control's site function ClientSite( obj: IUnknown ): IOleClientSite; var Site: IOleClientSite; OleObj: IOleObject; begin if (obj.QueryInterface( IOleObject, OleObj ) = S_OK) and (OleObj.GetClientSite( Site ) = S_OK) then Result := Site else Result := nil; end; // This function returns TRUE if the contained object's container is in // design mode; FALSE if the container is not in design mode or // does not support design mode, or on any failure. // function IsControlInDesignMode( obj: IUnknown ): Boolean; var Mode: Boolean; begin try Mode := not ((ClientSite(obj) as IAmbientDispatch).UserMode); except Mode := False; end; Result := Mode; end;