Partager via


Adding Properties and Methods to a Form

You can add as many new properties and methods as you want to a form set or to a form that isn't part of a form set. Properties hold a value; methods hold procedural code to be run when you call the method. The new properties and methods are scoped to the form and you reference them the same way you reference other properties or methods of the form.

Creating New Properties

If you have a form set, properties and methods that you add in the Form Designer are scoped to the form set. If you don't have a form set, the properties and methods are scoped to the form.

To add a new property to a form

  1. From the Form menu, choose New Property.
  2. In the New Property dialog box, type the name of the property. You can also include a description of the property that can be displayed at the bottom of the Properties window.

Creating an Array Property

An array property is scoped to the form like any other property, but can be manipulated with the Visual FoxPro array commands and functions.

To create an array property

  1. Add a new property to the form.

  2. In the Name box of the New Property dialog box, type the name of the array property and include the size and dimensions of the array.

    For example, to create a two-dimensional array with 10 rows, you could type arrayprop[10,2] in the Name box of the New Property dialog box.

Array properties are read-only in design mode, but you can manage, redimension, and assign values to the elements of the array property at run time. For an example of using an array property, see Managing Multiple Instances of a Form".

Creating New Methods

You can add methods to the form that can be called the same way the form class methods can be called.

To create a new method for a form

  1. From the Form menu, choose New Method.
  2. In the New Method dialog box, type the name of the method. You can optionally include a description of the method.

You call a user-defined method the same way you call base class methods, using the following syntax:

ObjectName.MethodName

Your method can also accept parameters and return values. In this case, you call the method in an assignment statement:

cVariable = ObjectName.MethodName(cParameter, nParameter)

Including Predefined Constants

To use predefined constants in your methods or events (not to properties), you can include a header file in a form or a form set using #INCLUDE. A header file typically contains compile-time constants defined with the #DEFINE preprocessor directive.

To include a file in a form

  1. From the Form menu, choose Include File.

  2. In the Include File dialog box, specify the file in the Include File text box.

    -or-

    Choose the dialog button to open the Include dialog box and choose the file.

  3. Choose OK.

See Also

Addition of Objects to Forms | Adding User-Defined Objects to a Form | Manipulating Objects | Creating Forms | Defining Form Behavior | Editing Event and Method Code