Defining a Data Field
Go Up to Defining New Persistent Fields
A data field replaces an existing field in a dataset. For example, for programmatic reasons you might want to replace a Data.DB.TSmallintField with a Data.DB.TIntegerField. Because you cannot change a field's data type directly, you must define a new field to replace it.
Warning: Even though you define a new field to replace an existing field, the field you define must derive its data values from an existing column in a table underlying a dataset.
To create a replacement data field for a field in a table underlying a dataset
- Remove the field from the list of persistent fields assigned for the dataset, and then choose New Field from the context menu.
- In the New Field dialog box, enter the name of an existing field in the database table in the Name edit box. Do not enter a new field name. You are actually specifying the name of the field from which your new field will derive its data.
- Choose a new data type for the field from the Type combo box. The data type you choose should be different from the data type of the field you are replacing. You cannot replace a string field of one size with a string field of another size. Note that while the data type should be different, it must be compatible with the actual data type of the field in the underlying table.
- 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.
- Select Data in the Field type radio group if it is not already selected.
- Choose OK. The New Field dialog box closes, the newly defined data field replaces the existing field you specified in Step 1, and the component declaration in the data module or form's type declaration is updated.
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.