Condividi tramite


Operating the Class Designer

When you specify what class your new class is based on and the library to store the class in, the Class Designer opens.

The Class Designer provides the same interface that the Form Designer does, allowing you to see and edit the properties of your class in the Properties window. Code editing windows allow you to write code to be executed when events occur or methods are called.

Adding Objects to a Control or Container Class

If you base the new class on the control or container class, you can add controls to it the same way you add controls in the Form Designer: choose the control button on the Form Controls toolbar and drag to size in the Class Designer.

No matter what type of class you base the new class on, you can set properties and write method code. You can also create new properties and methods for the class.

IF you press and hold the CTRL key while dragging objects from the toolbar to a form class, you disengage the default snap-to-grid behavior.

Adding Properties and Methods to a Class

You can add as many new properties and methods to the new class as you want. Properties hold values; methods hold procedural code to be run when you call the method.

Creating New Properties and Methods

When you create new properties and methods for classes, the properties and methods are scoped to the class, not to individual components in the class.

To add a new property to a class

  1. From the Class menu, choose New Property.

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

  3. Specify the visibility: Public, Protected, or Hidden.

    A Public property can be accessed anywhere in your application. Protected and Hidden properties and methods are discussed in Protecting and Hiding Class Members.

  4. Choose Add.

    You can also include a description of the property that will be displayed at the bottom of the Properties window in the Class Designer and in the Form Designer when the control is added to a form.

    Caution   When you add a property to a class that can be set by a user of the class, the user could enter an invalid setting for your property that could cause run-time errors. You need to explicitly document the valid settings for the property. If your property can be set to 0, 1, or 2, for example, say so in the Description box of the New Property dialog box. You might also want to verify the value of the property in code that references it.

To create an array property

  • In the Name box of the New Property dialog box, specify the name, size, and dimensions of the array.

    For example, to create an array property named myarray with ten rows and two columns, type the following in the Name box:

    myarray[10,2]
    

The array property is read-only at design time and is displayed in the Properties window in italics. The array property can be managed and redimensioned at run time. For an example of using an array property, see Managing Multiple Instances of a Form, Creating Forms.

To add a new method to a class

  1. From the Class menu, choose New Method.
  2. In the New Method dialog box, type the name of the method.
  3. Specify the visibility: Public, Protected, or Hidden.
  4. Select the Access check box to create an Access method, select the Assign check box to create an Assign method, or select both check boxes to create Access and Assign methods.

Access and Assign methods let you execute code when the value of a property is queried or when you attempt to change the property's value.

The code in an Access method is executed when the value of a property is queried, typically by using the property in an object reference, storing the value of the property to a variable, or displaying the value of property with a question mark (?).

The code in an Assign method is executed when you attempt to change the value of a property, typically by using the STORE or = command to assign a new value to the property.

You can also include a description of the method.

See Also

Object-Oriented Programming | Classes and Objects: The Building Blocks of Applications | Classes in Visual FoxPro | Preparation for Class Creation | Creating Classes | Modifying a Class Definition | Subclassing a Class Definition | Class Member Protection and Hiding | Specifying Design-Time Appearance for a Class | Creating, Copying, and Removing Class Library Files | Adding Classes to Forms | Default Property Setting Override | Container Hierarchy Object Referencing | Setting Properties | Calling Methods | Event Response