How to: Create Classes and Subclasses

You can create classes and subclasses using the Visual FoxPro Class Designer or programmatically. When you use the Class Designer to create classes, you can view the class as you design it.

Tip

For convenience and speed, you might want to keep a class and all its subclasses in one class library. If you have a class that contains elements from different class libraries, these libraries must all be open, so it might take longer to initially load the class at design time and run time.

To create a class or subclass

  1. On the File menu, choose New.

  2. In the New dialog box, choose Class, and then click New File.

    The New Class dialog box opens.

  3. In the Class Name box of the New Class dialog box, type the name of the class.

  4. In the Based On box, select the name of a Visual FoxPro base class.

    Tip

    To create a user-defined class, choose Custom as the base class. When you choose the Custom base class, the class you create is a non-visual class, which displays a visual element at design time but not at run time. For more information, see Custom Object and How to: Specify Design-Time Appearance for Classes.

    -OR-

    Click the ellipsis (...) button to select a visual class library (.vcx) file.

  5. In the Store In box, type the name of the class library file for storing the class.

  6. Click OK.

    The Class Designer opens and displays the class.

  7. When you are finished with creating the class, save the class.

    The class is saved in a Visual FoxPro visual class library (.vcx) file.

Visual FoxPro stores classes you create using the Class Designer in visual class library (.vcx) files. These classes include visual and non-visual classes.

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

You can also add classes and subclasses to an existing class library. For more information, see How to: Add Classes and Subclasses to Class Libraries.

To create classes or subclasses in a project

  1. Open the project for your application.

  2. In the Project Manager, choose the Classes tab, and click New.

    The New Class dialog box opens so you can specify information for the new class or subclass.

  3. Follow the steps for creating a class or subclass.

For more information, see Project Manager Window.

To create classes and subclasses programmatically

  • Use the CREATE CLASS command or DEFINE CLASS command.

The CREATE CLASS command opens the Class Designer, while the DEFINE CLASS command is for programmatic use. You can also create and add properties and methods and add code to respond to events for the class by using the DEFINE CLASS command.

Note

If you store class definitions in a program (.prg) file when you use DEFINE CLASS, you can precede, but not follow, class definitions with program code. This is similar to not following procedures with program code in a program.

For more information, see CREATE CLASS Command and DEFINE CLASS Command.

See Also

Tasks

How to: Modify Classes
How to: Add Properties to Classes
How to: Add Methods to Classes

Concepts

Classes in Visual FoxPro
Working with Classes in Visual FoxPro