The Seven Gotchas of ActiveX | |
---|---|
Although ActiveX control development is relatively straightforward, be sure to watch out for these seven gotchas:
1. Run time vs. design time isn't so simple any more. When you place a control on a form, VB puts it into runtime mode automatically. This means that if you build a control with other controls embedded in it, you won't be able to change their design-time properties once you place the new control on the form. You can solve this by either drawing your own controls or becoming an API guru and learning to use the standard window classes. 2. The Extender object adds properties to all controls, such as Name, Visible, Index, and so on. The container holding the control is supposed to provide the properties, but it isn't required to. You'll get a runtime error if you try to use any unsupported properties, so be sure to use error trapping. 3. The UserControl object is the "form" that you build your control on. It contains the properties and methods necessary for manipulating that form. You cannot pass the UserControl object into a BAS module or access it anywhere else but in the control, which is a real problem for subclassing operations. Refer to the main text of the article for the grim details. 4. Although ActiveX controls are classes just like ActiveX DLLs, you can't build public, creatable classes into them. You can include the class inside the control and include the class module in a project. This way, you can use early binding on any procedures or properties. Or, you can create an instance of the class and expose it to the outside. The class object will be late-bound, so you won't have any type checking. 5. Not all containers support the Ambient.UserMode property. This essential property tells you if the control is in runtime or design-time mode. Worse yet, if the container doesn't support this property, it always returns the default value (True). All unsupported Ambient properties behave this way. 6. The InvisibleAtRunTime property keeps your control from being put on a container. Not all containers support this property, so your controls might become visible anyway. Handle this manually by checking the Paint event and using the Extender's visible property to make the control invisible again. 7. You're on your own for OLE support. ActiveX controls support some OLE events, but you'll have to find another solution for what's missing. |