vb logo

 

Visual Basic Books
Home
Visual Basic Beginner Books
Visual Basic Database Books
Visual Basic ActiveX Books
Visual Basic Advanced Books
VB Internet Programming Books

Resources
Free Online Visual Basic Courses
Visual Basic Links
Add a Link
Subscribe to Mailing List

Visual Basic Books

Programming Components with Microsoft Visual Basic 6.0

Creating
ActiveX Controls

For example, the ambient property BackColor informs a control of the background color of its container. This can then be used to set the control’s own background color to blend better with the container. Ambient properties don’t need to be obeyed strictly, but it is polite to do so when it makes sense. Visual Basic makes ambient properties available to your control through an AmbientProperties object, a reference to which is available in the Ambient property of the UserControl object. This leads to this syntax for accessing ambient properties:

UserControl.Ambient.AmbientPropertyName

Ambient properties are properties of the UserControl object and are therefore available to the control only. They neither appear in the finished control’s Property window list nor are they available to applications that use the control.

Since the container provides ambient properties, some containers might not implement all the ambient properties. For example, if your ActiveX control is used in an application created in Borland’s Delphi, it is possible that all ambient properties won’t be available to your control. To circumvent this problem, the AmbientProperties object implemented by Visual Basic contains all of the standard ambient properties defined by the ActiveX controls specification, regardless of whether they are actually provided by the container. If a container doesn’t implement a particular ambient property, the AmbientProperties object simply returns a default value. This is advantageous because you don’t have to worry about getting error messages when using an ambient property that is not available.

By the same token, some containers might implement additional ambient properties. These properties will not be visible in the Object Browser because they are not in Visual Basic’s type library; nonetheless, the AmbientProperties object will expose them. You can learn about such properties in the documentation for a container and then access them as properties of the AmbientProperties object. Note that since these additional properties are not in the type library, Visual Basic cannot verify their existence at compile time. Therefore, you should use error handling when working with these properties; it is likely that your control will be used in another container where these properties might not be available.

As a consequence of this lack of type library information, any calls to container-specific ambient properties are late-bound. By contrast, any calls to standard ambient properties are early-bound. Recall that early binding requires type library information to be available at compile time so that all information regarding the object’s interface is obtained. Late binding uses the IDispatch interface, so no interface information is sought at development time, and thus no error checking can be performed. Instead, all the finding and creating of the object is deferred to run time. In Visual Basic, a call to CreateObject always signifies late binding, while setting a reference to an interface by means of the References dialog box indicates early binding.

next page....
Email us your comments:mail
Fax: 1(916)404-7719
©1999 Valassis Enterprises. All rights reserved.