Visual Basic Concepts
Features of Visual Basic ActiveX Components
See Also
With Visual Basic you can create components ranging from code libraries to Automation-enabled applications. You can create and distribute ActiveX control packages, with full licensing capability, or Internet applications with ActiveX documents that can display themselves in Internet browsers. With the Enterprise Edition of Visual Basic, you can run code components — such as business rule servers — on remote computers.
Figure 1.1 shows a Visual Basic application that uses several components, all of them built with Visual Basic.
Figure 1.1 Visual Basic application using components
Visual Basic ActiveX components are Internet- and intranet-enabled. Figure 1.2 shows a business analyst viewing a form on his desktop computer at the home office, while a sales representative views the same information through a Web page, using a Visual Basic ActiveX document.
Figure 1.2 Visual Basic activates the Internet
Which Type of Component Should I Build?
With all the different types of ActiveX components to choose from, how do you decide which type of component is best for a given situation? It may help to think of them in terms of functionality:
- If you need an invisible component that provides a service, you’ll want to build a code component — either an ActiveX Exe or an ActiveX DLL.
- If you need a component that can run in the same process with your application, you’ll want an ActiveX DLL. An example of this would be a component that performs complex calculations.
- If you need a component that can serve multiple applications and can run on a remote computer, you’ll want an ActiveX Exe. For example, a business rules server that enforces tax rules would best be implemented as an ActiveX Exe.
- If you need a visible component that can be dropped into an application at design time, you’ll want to build an ActiveX control. An example of this might be a phone number control that properly formats and validates phone numbers; such a control would undoubtedly be useful in many applications.
- If you need a visible component that can take over an application window at run time, choose an ActiveX document. The above example shows a sales application that can be viewed in a Web browser, duplicating the functionality of a desktop application.
No matter which type of ActiveX component you choose to build, Visual Basic makes reusability a reality.
Features for Building Components
The following are some of the features Visual Basic provides for creating software components.
- Components can provide several types of objects, as described in the related topics "ActiveX Controls," "ActiveX Documents," "Code Components," and "Applications that Provide Objects."
- Objects provided by components can raise events. You can handle these events in a host process or in another application — with the Enterprise Edition, such an application can even be running on a remote computer.
- Components can be data-aware, binding directly to any source of data without the need for a data control. You can also create an ActiveX component that acts as a data source to which other objects can bind. For example, you could create your own data control (similar to the ADO Data control or the Remote Data control), but instead of binding via ADO or RDO you could bind to a flat file or a proprietary binary data format.
- Friend functions allow the objects provided by a component to communicate with each other internally, without exposing that communication to applications that use those objects.
- The Implements keyword lets you add standard interfaces to your objects. These common interfaces enable polymorphic behavior for objects provided by a component, or for objects provided by many different components.
- You can use enumerations to provide named constants for all component types.
- You can choose a default property or method for each class of object your component provides.
- You can allow users of your component to access the properties and methods of a global object without explicitly creating an instance of the object.
These features are discussed in detail in "General Principles of Component Design," along with other subjects relevant to all component types.
For More Information Components that perform computation-intensive tasks may benefit from compilation to native code. This subject is covered in "More About Programming" in the Visual Basic Programmer’s Guide.