jwcolby
jwcolby at colbyconsulting.com
Tue Feb 17 15:21:52 CST 2009
Now that we have a class for the label control it is time to integrate it into the control classes. We will start with clsCtlCbo. • In the demo database, open clsCtlLbl • In the header add the following code: Private mclsCtlLbl As clsCtlLbl This code dimensions a new variable to hold our label class. • Using the two combos select Class and add the Initialize event stub. • Add the following code to the initialize stub: Private Sub Class_Initialize() Set mclsCtlLbl = New clsCtlLbl End Sub I always initialize new objects such as classes, collections, recordsets etc. in the Initialize event. • In Class_Terminate add the following code: Private Sub Class_Terminate() Set mctlTxt = Nothing Set mclsCtlLbl = Nothing End Sub This cleans up the label class when clsCtlCbo class closes. • At the bottom of mInit() add the following code: mclsCtlLbl.mInit lctlTxt Since mclsCtlLbl was initialized in the Initialize event of the class it is ready to use when we get to mInit. We simply call the mInit method of mclsCtlLbl and pass in the combo control passed in to clsCtlCbo. • Directly underneath mInit add the following property code: Property Get cCtlLbl() As clsCtlLbl Set cCtlLbl = mclsCtlLbl End Property This property allows the parent class to access mclsCtlLbl. It is quite common for classes to initialize and use other classes. It is often useful to expose those classes to other code in the system and we can do that by a property that returns the pointer to the class. In this lecture we dimensioned a new variable in the class header of clsCtlCbo to hold an instance of clsCtlLbl. In the class Initialize event we initialized mclsCtlLbl. In the Terminate event we cleaned up mclsCtlLbl. In mInit we added code to call the mInit() of mclsCtlLbl passing in the same control that was passed in to clsCtlCbo. Finally, we added a new property to clsCtlCbo to expose our instance of clsCtlLbl. This basic pattern will be repeated in all of our clsCtlXXX classes in order to add a clsCtlLbl to each class. Please repeat the process for clsCtlTxt now. -- John W. Colby www.ColbyConsulting.com