Partilhar via


How to: Add Methods to Classes

After you create a class, you can create and add custom methods to the class. When you add methods to classes, you are creating a procedure or function in the class definition. For more information about methods, see Classes in Visual FoxPro.

Note

When you create custom methods for classes, the methods are scoped to the class, not to individual components in the class. If you create a method that has the same name as an event in the class definition, the code in the method executes when the event occurs.

You can add methods to classes using the Visual FoxPro IDE or programmatically. When you add a method, you can specify the level of visibility for the method. For more information about visibility levels for methods, see Protecting and Hiding Class Members.

To add a method to a class

  1. Open the class in the Class Designer.

    For more information about opening classes, see How to: Modify Classes.

    When the class opens in the Class Designer, the Class menu appears.

  2. On the Class menu, choose New Method.

  3. In the Name box of the New Method dialog box, type the name of the method.

  4. In the Visibility box, choose the visibility level for the method.

  5. To specify a description for the method when the method appears in the Properties window, include a description in the Description box.

  6. Click Add.

  7. Continue adding methods, or if you are finished, click Close.

After you add the method, it appears in the Properties window at the end of the properties list. For information about adding code to methods, see How to: Add Code to Methods and Events.

To add methods to classes programmatically

  • Use the DEFINE CLASS command and include the FUNCTION clause when you create a class.

For more information, see DEFINE CLASS Command.

See Also

Tasks

How to: Add Properties to Classes

Concepts

Working with Classes in Visual FoxPro