The Class Instancing Property

As you’ve noticed Classes have a few properties. In this chapter we discuss only . two of them: the Name property and the Instancing property. The instancing property determines whether and how applications can use the Class. Its six possible settings are discussed next.

Private

Private objects can only be accessed by components in the same application. If you’re developing a Class that can’t be used in other projects or yo don’t want to make it available to other developers set its Instancing property to Private.

Single Use

nus setting applies to ActiveX EXE code components only.An ActiveX EXE server is an executable file (an application) that can service one or more clients. If the server’s Instancing property is Single Use, for every client that calls the Class’ objects a new
instance of the server is started. This setting is an inefficient method of creating and using objects and it’s usually avoided. If you need a new instance. of the server for each client you might as well implement the server as an ActiveX DLL.

Multi Use

This setting is-the opposite of Private and can be used with code components only. It allows a single instance of the server to provide as many objects as are required by the client applications. Every new ActiveX EXE or ActiveX DLL project you start has its Instan Cing property set to Multi Use by default.

Global Single use

This setting creates a global object with Single Use characteristics. If you’re going to implement a global object make it Single use so that all clients that call it can . be serviced by a single instance of the server. It’s also available with Activex EXE and ActiveX DLL components.

Global Multi Use

This setting is available with ActiveX EXE and ActiveX DLL projects and should be used rarely. The objects exposed by Global Multi Use component are available to the entire system and can be accessed by any application as if they were system components. Visual Basic provides system-wide objects called global objects. For example the Screen and Printer objects are global objects because you don’t need to add a reference to them in the applications that use them. If you think you have an object that’s important for the rest of the system to know about (and not just the
application that needs it); then set its Instancing property to Global Multi Use.

Public Not Creatable

The objects of a Class with this setting can be accessed by other applications but can’t be created. Now what good is this? The objects of a Public Not Cr eatable Class must be first created by another component in the same object and then accessed through this component’s objects. For example if you have a class that implements database operations one of the objects exposed by the Class represents the database. Another Class in the project represents a Table of the database. If you allow the developers access the second object directly there’s a chance he may attempt to open the Table without first opening the database. Instead if you make the Class that exposes the Database object Multi Use and the Class that exposes the Table object Private Not Cr eatable and then you create a reference to the object  hat represents the table 8S soon as the database is opened the developer can access the Table object directly but only after it has been created.

The remaining properties of the Class object are briefly described but will not be used in this book:

Data Binding Behavior

Determines whether the Class will act as a data consumer (a Class that connects to databases and provides records and/ or fields to he host application)

Data Source Behavior

Determines whether the Class can be used as a data source (whether other Classes of controls can be bound to this Class)

MTS Transaction Mode

Allows you specify whether the Class will support the Microsoft Transaction Server. This setting will be.used for Classes meant to be executed on a server and carry out multiple transactions at once. If one of the transactions fails then all transactions are aborted.

Scroll to Top