Creating the Run-Time Object

When the end user wants to compile or run the application, the ActiveX designer creates a run-time object. First, Visual Basic calls IProvideClassInfo or IProvideDynamicClassInfo to get the type information it needs to create the object.

Before compiling the application or shifting into run mode, Visual Basic asks the ActiveX designer to save the prototypical instance state for the run-time object. If the visual designer implements the IActiveDesigner interface, Visual Basic calls its SaveRuntimeState method to save the data. If not, Visual Basic uses the Save method of the visual designer's persistence interface, in the following order of preference:

Persistence and the IActiveDesigner interface are described in greater detail in Chapter 7, "Retaining Persistent Data and Saving the Run-Time Object."

Finally, at execution time, Visual Basic takes the following steps, shown in the figure, to create the ActiveX designer's run-time object. It calls:

  1. CoCreateInstance, passing the CLSID saved with the persistent data. The class factory for the run-time object ensures that it is properly licensed.
  2. Load method of the persistence interface to load persistent data for the new object.
  3. IConnectionPointContainer or IConnectionPoint to connect run-time events with the event handlers defined in the ActiveX designer. Run-time objects must support events.

An end user can create additional instances of a class defined by an ActiveX designer by using the New operator in Visual Basic code. Like form classes, but unlike ActiveX controls and public class modules, the classes produced by ActiveX designers are private classes. Accoringly, users of the Professional or Enterprise editions of Visual Basic who create ActiveX components cannot declare public methods that use these classes as argument types or return types.