Using a Variable as a Parameter for CreateObject()Last reviewed: April 30, 1996Article ID: Q130460 |
The information in this article applies to:
SUMMARYCreateObject() takes a classname as a parameter. This article shows by example how to set a variable equal to the classname, and than use that variable as the parameter for every CreateObject() function for that class. Should the class later be subclassed, you only need to change the variable name from the old classname to the new subclass name; only a single line of code had to change.
MORE INFORMATIONThe following program, which does not use the variable to hold the classname, creates three blank forms with a white backcolor. The program also defines GreyForm as a subclass of Form. It has its backcolor set to grey. To base each form off of the GreyForm class instead of the Form class, requires that each occurrence of createObject('Form') be replaced with CreateObject('GreyForm'). x=CreateObject('Form') y=CreateObject('Form') z=CreateObject('Form') x.visible=.T. y.visible=.T. z.visible=.T. DEFINE CLASS GreyForm as Form BackColor=RGB(192,192,192) Caption="Grey"ENDDEFINE The following program is identical in function to the first one. However, it uses a variable to hold the classname. Now you need only change the first line to cForm="GreyForm" to base all of the forms off of the GreyForm subclass. cForm="Form" x=CreateObject(cForm) y=CreateObject(cForm) z=CreateObject(cForm) x.visible=.T. y.visible=.T. z.visible=.T. DEFINE CLASS GreyForm as Form BackColor=RGB(192,192,192) Caption="Grey"ENDDEFINE
|
Additional reference words: 3.00 VFoxWin KBfest
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |