CREATEOBJECT( ) Function Example

The following example uses DEFINE CLASS and CREATEOBJECT( ) to create two custom classes named FormChild and FormGrandChild from the Visual FoxPro Form base class. ACLASS( ) is used to create an array named gaNewarray containing the class names, which are then displayed.

CLEAR

* Verify current class library setting
cCurClassLib=SET("CLASSLIB")
IF LEN(ALLTRIM(cCurClassLib))=0
   cCurClassLib="None"
ENDIF

WAIT WINDOW "Current class library is: " + cCurClassLib + CHR(13);
   + "Press any key to continue..."

frmMyForm = CREATEOBJECT("FormGrandChild")

* Create an array
FOR nCount = 1 TO ACLASS(gaNewarray, frmMyForm)
   ? gaNewarray(nCount)  && Display the names of the classes
ENDFOR

RELEASE frmMyForm

* Create FormChild from FORM baseclass
DEFINE CLASS FormChild AS FORM
ENDDEFINE

* Create FormGrandChild from user-defined FormChild class
DEFINE CLASS FormGrandChild AS FormChild
ENDDEFINE