Defining a Calculated Field

From RAD Studio
Jump to: navigation, search

Go Up to Defining New Persistent Fields


A calculated field displays values calculated at run time by a dataset's OnCalcFields event handler. For example, you might create a string field that displays concatenated values from other fields.

To create a calculated field in the New Field dialog box

  1. Enter a name for the calculated field in the Name edit box. Do not enter the name of an existing field.
  2. Choose a data type for the field from the Type combo box.
  3. Enter the size of the field in the Size edit box, if appropriate. Size is only relevant for fields of type Data.DB.TStringField, Data.DB.TBytesField, and Data.DB.TVarBytesField.
  4. Select Calculated or InternalCalc in the Field type radio group. InternalCalc is only available if you are working with a client dataset. The significant difference between these types of calculated fields is that the values calculated for an InternalCalc field are stored and retrieved as part of the client dataset's data.
  5. Choose OK. The newly defined calculated field is automatically added to the end of the list of persistent fields in the Field editor list box, and the component declaration is automatically added to the form's or data module's type declaration.
  6. Place code that calculates values for the field in the Programming a calculated field.

Note: To edit the properties or events associated with the field component, select the component name in the Field editor list box, then edit its properties or events with the Object Inspector. For more information about editing field component properties and events, see Setting persistent field properties and events.

See Also