Compartir a través de


DEFINE CLASS Command - DEFINE CLASS Clause

Specifies the name of the class to create and the parent class used to create the new class. You can also make it possible for Automation clients to access the class when included in an Automation server.

DEFINE CLASS ClassName1 AS ParentClass [OF ClassLibrary] [OLEPUBLIC]
[Other DEFINE CLASS clauses]

Parameters

  • DEFINE CLASS ClassName1 AS ParentClass
    Specifies the name of the class to create and the parent class to use as the base class. The parent class can be a Visual FoxPro base class, such as the Form class, or another user-defined class or subclass. You can also create subclasses from the Exception and Session classes in addition to the Visual FoxPro base classes.

    Note

    If you specify Custom as ParentClass, Visual FoxPro creates a non-visual user-defined class. If you specify Session as ParentClass, Visual FoxPro creates a non-visual user defined class that maintains its own private data session. The ADD OBJECT clause is not available when you specify Session as ParentClass because a Session object is not a container. For more information, see Session Object.

    For more information about Visual FoxPro base classes, see Base Classes in Visual FoxPro.

    You can also use the AS clause to implement strong typing. IntelliSense functionality is available for object and variable references only when they are strongly typed. For more information, see How to: Implement Strong Typing for Class, Object, and Variable Code.

  • [OF ClassLibrary]
    Makes it possible for you to specify a class library for AS ParentClass without needing to explicitly specify the path to the class library containing it as when using the SET CLASSLIB or SET PROCEDURE commands. ClassLibrary can be a class library (.vcx), program (.prg), or compiled program (.fxp) file.

    The specified ClassLibrary can contain a relative path as long as Visual FoxPro can locate the library along its usual class library searching paths. If Visual FoxPro cannot find the specified ClassLibrary when you attempt to instantiate an instance of the class, Visual FoxPro generates an error.

    Visual FoxPro adds ClassLibrary to the project during the build process automatically if the program containing the class is included in the project.

    When using the OF ClassLibrary clause, be sure that the current program does not have same class name as that specified in the OF ClassLibrary clause.

    Note

    If an OF <ProgramFile> reference is used in a program that is bound inside of an executable application, the <ProgramFile> name should have an .fxp file name extension and not a .prg extension.

  • [OLEPUBLIC]
    Specifies that Automation clients can access the class when included in an Automation server.

    Note

    If you include the OLEPUBLIC keyword for a class whose base class is Session, the type library generated for an executable (.exe) or dynamic-link library (.dll) contains only your custom properties and methods. All intrinsic properties, methods, and events of the Session base class are excluded from the type library. This behavior is supported in Visual FoxPro 7.0 and later.

    If you add a program with a class definition created as OLEPUBLIC to a project, you can create an .exe or a .dll file containing the class interactively using the Project Manager, the BUILD EXE, BUILD DLL, or BUILD MTDLL commands. The .exe or .dll registers with the operating system automatically and becomes available to any Automation client. For more information, see How to: Create Automation Servers, How to: Build Applications, BUILD EXE Command, BUILD DLL Command, or BUILD MTDLL Command.

  • ENDDEFINE
    Indicates the end of the class definition.

Remarks

The following code shows a summary of the main clauses of the DEFINE CLASS command:

DEFINE CLASS Clause
   [Property_Definition_Clause]
   [PEMName_COMATTRIB Clause]
   [ADD OBJECT Clause]
   [IMPLEMENTS Clause]
   [Function_Procedure_Definition_Clause]
ENDDEFINE

For more information and full syntax, see DEFINE CLASS Command. For more information about a particular clause of the DEFINE CLASS command, see the following topics:

Example

The following example creates a class named MyForm from the Form base class and creates a protected property named Version. The class also contains another property called Caption, which is not protected. The class definition initializes the default values of Version and Caption to the strings "1.0" and "My Form", respectively.

DEFINE CLASS MyForm AS Form
   PROTECTED Version
   Version = "1.0"
   Caption = "My Form"
ENDDEFINE

See Also

Reference

:: Scope Resolution Operator

ADD CLASS Command

CREATE CLASS Command

CREATE CLASSLIB Command

DODEFAULT( ) Function

EVENTHANDLER( ) Function

GETOBJECT( ) Function

MODIFY CLASS Command

RELEASE CLASSLIB Command

Other Resources

Commands (Visual FoxPro)