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.
ActiveX designers are like form designers in the following ways:
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
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.
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.
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
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."