HOWTO: Enforce Initialization of a VB OLE Class ObjectLast reviewed: May 16, 1997Article ID: Q138065 |
The information in this article applies to:
SUMMARYThis article suggests a way to enforce the proper initialization of a Visual Basic OLE object that is instantiated from a class module. The class module has an Initialize event that is invoked each time an object of that class is instantiated. However, it is not possible to pass any parameters to the Initialize event of a class module. To implement an object constructor that takes parameters to properly initialize the object's members, you can define a Public method (called Create for example) in the class module and call it with parameters immediately after instantiating the object.
MORE INFORMATIONThe following step-by-step example shows how to implement a Create Method that enforces proper object instantiation. Note that the following statement must be the first statement in each method or property procedure in the class module:
If blnNotCreated Then Err.Raise vbObjectError, "MyServer", _ "Object Not Yet Created! Please Call the Create Method First"This will raise an error that is returned back to the client in case the Create Method is not called. Note also that the flag blnNotCreated is the only member that is set in the Initialize event. This is done to avoid the following action, which would result in the unnecessary overhead of the Not operator:
If Not blnCreated then Err.Raise Step-by-Step Example for Creating the Server
Step-by-Step Example for Creating the Client
|
Keywords : IAPOLE kbcode vb4all vb4win kbhowto
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |