Author: Christopher Brandsma
How to find out if your ActiveX control is running in Design mode or Run mode
Every now and then an ActiveForm developer will want to add a feature to an ActiveX
control that only shows up in either Design-Time or Run-Time (splash screens and
nag screens are an example). (Background: Design-Time is when a control is applied
to a form in the Visual Basic environment; Run-Time is when the control is running
inside of an executable). If you are using TActiveXControl as youíre base object,
you get this for free. If you are using TActiveForm you have to work for the
The property we need is UserMode. If this property is True we are in Run-Time
mode; if False we are in Design-Time mode. UserMode is one of the AmbientProperties
that a controlís container is supposed to provide. Delphi even supplies an
interface call IAmbientDispatch in AxCtrls for retrieving the ambient properties.
To get it: Your ActiveForm has a property called ActiveFormControl.ClientSite.
This property is set sometime before your control's OnShow event (ClientSite will
not be set in the constructor or the initialize procedures). Cast ClientSite to an
IAmbientDispatch (found in AxCtrls), then get the UserMode property. (see code
1 procedure TDesignCtrl.HandleOnShow(Sender: TObject);
2 var3 b: Boolean;
4 pIAmbient: IAmbientDispatch;
5 begin6 pIAmbient := Self.ActiveFormControl.ClientSite as IAmbientDispatch;
7 b := pIAmbient.UserMode;
8 9 if b then10 ShowMessage('is in runtime mode')
11 else12 ShowMessage('is in design mode');
There are other properties in the IAmbientDispatch interface that could also be useful to a control writer so feel free to experiment.