JavaScript Editor js editor     Web development 

Main Page

When you create a class, you can add custom properties to the class. For more information about properties, see Classes in Visual FoxPro.

When you create custom properties for classes, the properties apply to the class, not to individual components in the class.

You can add properties to classes using the Visual FoxPro IDE or programmatically.

To add a property to a class

  1. Open the class in the Class Designer.

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

  2. On the Class menu, choose New Property.

  3. In the Name box of the New Property dialog box, type the property name.

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

  5. To create an Access method, select Access Method. To create an Assign method, select Assign method. To create both Access and Assign methods, select both boxes.

  6. To specify a default value other than False (.F.) for the property, include a different default value in the Default Value box.

    To set the default value of a property an empty string (""), click in the Default Value box and press the SPACE key.

  7. To specify a description to display for the property in the Properties window, include a description in the Description box.

    You can document valid property values in the Description box.

  8. Click Add.

  9. Continue adding properties, or if you are finished, click Close.

Properties in subclasses inherit the default property values that you specify unless you reset the default values to those of the parent class. When you add a property that can be set by the user, the user might enter an invalid property value that can cause run-time errors. It is recommended that you include code in your application that validates values entered for the property or that you document the valid property values.

After you add the property, it appears in the Properties window at the end of the properties list along with any default value that you specified. You can change values for the property in the Properties Window (Visual FoxPro).

For more information about opening classes, see How to: Modify Classes. For more information about visibility levels for properties, see Protecting and Hiding Class Members. For more information, see Access and Assign Methods and How to: Create Access and Assign Methods.

To add properties to classes programmatically

  • Use the DEFINE CLASS command.

    At run time, you can add properties to objects by using the ADDPROPERTY(В ) function or the object's AddProperty method.

For more information, see DEFINE CLASS Command, ADDPROPERTY( ) Function, and AddProperty Method.

Array Properties

You can create and add array properties to a class. Array properties are arrays that you can add to the class as properties. An array property is read-only at design time and appears in italic in the Properties window; however, you can manipulate and redimension an array property at run time. For example, you can create an array property for a form to store object variables associated with each instance of a form. For an example of using an array property, see How to: Manage Multiple Instances of a Form. For information about limits on the number of elements in arrays, see Visual FoxPro System Capacities.

To create an array property

  1. Follow the steps for adding a property to a class.

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

For example, specifying myArrayProperty[10,2] creates an array property named myArrayProperty with ten rows and two columns.

See Also

JavaScript Editor js editor     Web development