You are here: Visual
Basic > Advanced VB6 tutorial
> Chapter 4
Keeping a Reference in the Project to an ActiveX Control in Visual Basic
6
When you create an exe or run your project
in the IDE, VB6 by default removes references
to ActiveX controls that are in the Toolbox
but not used by the program. VB is able to remove
this extraneous reference information by checking
to see whether instances of a control exist
on the surfaces of forms or other container
objects.
However, VB6 cannot detect when an ActiveX control of a particular type is
going to be added to the control array, because the type of such a control is
declared as VBObjectExtender. The control object is
therefore late bound and the compiler cannot verify its existence in the project.
Thus, the VB6 compiler may remove information
about a control type that you want to add to
the Controls Collection if you have placed the
control in the Toolbox and you have not put
design time instances of that control in your
project.
When your code attempts to initialize such
a control, the compiler will give you an error
message warning that a reference is lacking
(see Figure 4.17).

FIGURE 4.17 Compiler error for a deleted
reference to an ActiveX control.
The warning illustrated in Figure 4.17 also
tells you what to do in order to keep the reference
to the control in your application:
Change the default compiler behavior by un-checking
the option labeled Remove information about
unused ActiveX Controls in the Make tab of the
Project Properties dialog box (see Figure 4.18).
If you un-check this option, then you will not
receive the message of Figure 4.17 again.

FIGURE 4.18 The Make tab of the Project
Properties dialog showing the option that controls
references to unused ActiveX controls.
Of course another way to avoid this situation is by simply removing the control
from the Toolbox if you don't plan to place design time instances of it in your
project (uncheck the control's library in the Project Components dialog). The
system will still recognize your reference to the control's ProgID in the Controls.Add
method and will instantiate the correct control type.
Adding and Deleting Controls Dynamically Using the Controls Collection
Topics
Related Topics
See Also
<< Previous | Contents
| Next >>
|