Declarations, Events, and Methods

As you can see near the top of this object's source code, the m_oc variable is declared to be an MTS ObjectContext object:

Private m_oc As MTxAS.ObjectContext

In this declaration, the Visual Basic New keyword is not used. Including New would forestall its instantiation until the object is first referenced. Later sections discuss the use of the New keyword in more detail.

Note  This MTS object is not the same as the built-in ASP ObjectContext object. For more information about these MTS and ASP objects, query for "MTS ObjectContext object" or "ASP ObjectContext object" in the Microsoft Platform SDK on the Microsoft Developer Network (MSDN™) CD-ROM.

After the object declaration, the Class_Initialize and Class_Terminate subroutines are event declarations. The Class_Initialize event calls the MTS GetObjectContext function, which obtains a reference to the IObjectContext interface on the ObjectContext associated with the current MTS object, the just-instantiated m_oc object. Similarly the Class_Terminate event destroys the m_oc object.

The rest of this object's methods (CreateInstance, SetComplete, and SetAbort) are declared to be public and are thus accessible by the other components of the CML application. Their functioning is simple. First, each method verifies that it has a valid object context:

If Not m_oc Is Nothing Then . . .

CreateInstance has the same signature (set of parameters) as the CreateInstance method of the ObjectContext object. When passed a ProgID, it creates an instance of the object whose ProgID was passed. This causes the object to be created through the IDispatch interface.

The SetComplete and SetAbort methods are used with CML objects that perform transactions with the FmLib database. SetComplete and SetAbort let MTS manage the distributed nature of CML transactions by causing the transaction to be completed or rolled back, respectively. This they do by calling the SetComplete or SetAbort methods of the MTS ObjectContext object.