Automating the Creation of Properties with the Class Explorer

From RAD Studio
Jump to: navigation, search

Go Up to Delphi Class Explorer Topics

Using the Delphi Class Explorer you can automate the creation of properties.

You can use the Add Property dialog box to add to a class the code for the declaration of a property and for the default implementations of the getter and setter methods.

To automate the creation of properties:

  1. Open the Delphi Class Explorer window by choosing View > Class Explorer .
  2. In the Class Viewer pane, right-click a class into which you wish to add a property.
  3. On the context menu, choose the Add Property item. The Add Property dialog box appears.
  4. Into Property name type the name for the property to be added. This name will be used to generate the default names to the getter, setter, and field.
  5. In the Add to class combo box, select the class into which you wish to add the property. By default, the class currently selected in the Class Viewer pane is prompted. You can, however, change this to any other available class selecting it from the drop-down list in the combo box.
  6. In the Type combo box, select the type of the property value. You can select one of the predefined types from the drop-down list in the combo box or you can type in any other existing type.
  7. In the Visibility group select one of the visibility specifiers. The selected visibility specifier will be applied to the property being created.
  8. In the Reader and Writer combo boxes, specify the field or methods that will be used to read and write the property value.The default names based on the specified property name are prompted. You can, however, change these names to any other available methods selecting them from the drop-down list in the combo box or type them explicitly.

    Warning: Be careful selecting existing methods in the Reader and Writer combo boxes. If the selected methods already have implementations, then the code of these implementations can be silently deleted!

  9. Check ON the Create field check box to create a field that will store the property value.
  10. Click OK. The code for the property declaration and the default implementations of the specified getter and setter methods are inserted into the specified class.

See Also