Share via


Visual Basic Concepts

What Are ActiveX Designers?

ActiveX designers can provide visual interfaces for tasks that otherwise might require a great deal of code. For example, the UserConnection designer included in the Enterprise Edition of Visual Basic provides visual tools for defining complex database queries. At run time, these queries can be invoked with very little code.

Similarities between ActiveX Designers and Built-in Designers

ActiveX designers are like form designers in the following ways:

  • ActiveX designers produce classes from which you can create objects. These classes appear in the Project window, just like form classes.

  • Each class you create with an ActiveX designer has its own code module, in which you can write code for the event procedures provided by the designer.

  • You can customize a class, by adding your own properties, methods, and events to the ones provided by the ActiveX designer.

  • The objects created from classes you design can have different characteristics at design time and run time.

  • An ActiveX designer's design window is fully integrated into the development environment. It can be sized and arranged just like built-in design windows.

  • You can add as many instances of an ActiveX designer to your project as you need, just as you can add as many form designers as you need.

Figure 9.14 compares the built-in Visual Basic form designer with the UserConnection Designer, an ActiveX designer included in the Enterprise Edition of Visual Basic.

Figure 9.14   An ActiveX designer and a built-in Visual Basic designer

Comparing ActiveX Designer Classes to other Visually Designed Classes

ActiveX designers are extremely flexible. Some, like the UserConnection designer, create classes whose run-time instances are programmable, but not visible. Others, like the Microsoft Forms designer used by Microsoft Office, produce visible objects similar to Visual Basic forms.

ActiveX designers that have visible run-time components may be able to host ActiveX controls. In effect, they become alternate forms packages, which can be used in addition to Visual Basic's native forms.

The following list compares classes produced with ActiveX designers to those produced with built-in Visual Basic designers.

  • If an object created from an ActiveX designer class is visible at run time, it has its own window. It is not contained within another form, as ActiveX controls are.

  • Like form classes, but unlike ActiveX controls, the classes produced by ActiveX designers are private classes. If you're using the Professional or Enterprise Edition of Visual Basic to create ActiveX components, you cannot declare public methods that use these classes as argument types or return types.

    For example, the following method declarations produce compile-time errors if they appear in a public class:

    Public Function A() As UseConnection1       'Error
    Public Sub B(CallBack As UseConnection1)    'Error
    

Caution*   Although it is possible to pass references to private objects outside your project, by declaring return values As Object, this is very bad practice, and may destabilize your program. For more information, see Creating ActiveX Components in the *Component Tools Guide.

Using ActiveX Designer Objects at Run Time

Like the built-in form designer, ActiveX designers are available only in the development environment. Once you make your project into an executable, it only uses the ActiveX designer's run-time .dll. This may be much smaller than the design-time .dll, because it doesn't include the visual design tool. Figure 9.15 illustrates this concept.

Figure 9.15   Designer components in memory

As noted earlier, ActiveX designers may produce classes whose objects are not visible at run time. The UserConnection designer shown in Figure 9.14 is an example. The UserConnection designer produces classes whose objects manage connections to SQL databases at run time. There is no reason for these objects to be visible at run time.

To use a class created with the UserConnection designer, declare a variable of the class type and create an instance of the class. For example, if you added a UserConnection designer and set its Name property to GeneralLedger, you could create a GeneralLedger object as shown in the following code fragment:

' Global variable in a standard module, to keep a
' reference to the GeneralLedger object.
Public gGeneralLedger As GeneralLedger

' Code in a Form module to create the GeneralLedger
' object and establish a database connection.
Private Sub Command1_Click()
   Set gGeneralLedger = New gGeneralLedger
   gGeneralLedger.EstablishConnection
   ' (Code that uses the object.)
End Sub

Creating ActiveX Designers

You can use the ActiveX Designer Software Development Kit to create new ActiveX designers for use with Visual Basic. The SDK includes full instructions and sample code. You can find it on the Microsoft Development Network under the heading "SDK Documentation."

Note   The ActiveX Designer SDK requires a C++ compiler, such as Microsoft Visual C++. ActiveX designers cannot be written using Visual Basic.

For More Information   Procedures for incorporating ActiveX designers in your project are provided in "Adding an ActiveX Designer to the Project Menu" and "Inserting a New Instance of an ActiveX Designer."