Editing Data in a Control
Go Up to Using data controls Index
A data control can only post edits to its associated dataset if the dataset's CanModify property is True. CanModify is always False for unidirectional datasets. Some datasets have a ReadOnly property that lets you specify whether CanModify is True.
Note: Whether a dataset can update data depends on whether the underlying database table permits updates.
Even if the dataset's CanModify property is True, the Enabled property of the data source that connects the dataset to the control must be True as well before the control can post updates back to the database table. The Enabled property of the data source determines whether the control can display field values from the dataset, and therefore also whether a user can edit and post values. If Enabled is True (the default), controls can display field values.
Finally, you can control whether the user can even enter edits to the data that is displayed in the control. The ReadOnly property of the data control determines if a user can edit the data displayed by the control. If False (the default), users can edit data. Clearly, you will want to ensure that the control's ReadOnly property is True when the dataset's CanModify property is False. Otherwise, you give users the false impression that they can affect the data in the underlying database table.
In all data controls except TDBGrid, when you modify a field, the modification is copied to the underlying dataset when you Tab from the control. If you press Esc before you Tab from a field, the data control abandons the modifications, and the value of the field reverts to the value it held before any modifications were made.
In DBGrids.TDBGrid, modifications are posted when you move to a different record; you can press Esc in any record of a field before moving to another record to cancel all changes to the record.
When a record is posted, Delphi checks all data-aware controls associated with the dataset for a change in status. If there is a problem updating any fields that contain modified data, Delphi raises an exception, and no modifications are made to the record.
Note: If your application caches updates (for example, using a client dataset), all modifications are posted to an internal cache. These modifications are not applied to the underlying database table until you call the dataset's ApplyUpdates method.