Partilhar via


Visual Basic Concepts

Object Models for Controls

Complex controls such as TreeView and Toolbar provide run-time access to their functionality through objects. For example, the TreeView control has a Nodes collection containing Node objects that represent the items in the hierarchy the TreeView control displays. Users can create new nodes using the Add method of the Nodes collection.

Objects like Node and Nodes are called dependent objects. Dependent objects exist only as a part of some other object, as Node objects are always part of a TreeView control. They cannot be created independently.

You can provide dependent objects like Node and Nodes by including class modules in your ActiveX control project and organizing them into an object model. Object models can be as simple as the Nodes collection with its Node objects, or arbitrarily complex.

Important   Control components can only provide dependent objects. They cannot provide objects that can be independently created, using the New operator or the CreateObject function.

For More Information   Dependent objects are discussed in "Instancing for Classes Provided by ActiveX Components," in "General Principles of Component Design." Also, you can read about object models in "Organizing Objects: The Object Model," which is also in "General Principles of Component Design."

Some design considerations for collections in controls are discussed in "Creating Robust Controls," later in this chapter. More information on robust techniques for using objects can be found in "Private Communications Between Your Objects," in "General Principles of Component Design."

Classes, class modules, and objects are discussed in "Programming with Objects," in the Visual Basic Programmer's Guide.