Checking Update Status
Go Up to Using Cached Updates
When cached updates are enabled for your application, you can keep track of each pending update record in the cache by examining the UpdateStatus property for the record. Checking update status is most frequently used in OnUpdateRecord and OnUpdateError event handlers. For more information about creating and using an OnUpdateRecord event, see Creating an OnUpdateRecord Event Handler. For more information about creating and using an OnUpdateError event, see Handling Cached Update Errors.
As you iterate through a set of pending changes, UpdateStatus changes to reflect the update status of the current record. UpdateStatus returns one of the following values for the current record:
| Value | Meaning |
|---|---|
|
|
Record is unchanged |
|
|
Record is changed |
|
|
Record is a new record |
|
|
Record is deleted |
When a dataset is first opened all records will have an update status of usUnmodified. As records are inserted, deleted, and so on, the status values change. Here is an example of UpdateStatus property used in a handler for a dataset’s OnScroll event. The event handler displays the update status of each record in a status bar.
procedure TForm1.CustomerQueryAfterScroll(DataSet: TDataSet);
begin
with CustomerQuery do begin
case UpdateStatus of
usUnmodified: StatusBar1.Panels[0].Text := 'Unmodified';
usModified: StatusBar1.Panels[0].Text := 'Modified';
usInserted: StatusBar1.Panels[0].Text := 'Inserted';
usDeleted: StatusBar1.Panels[0].Text := 'Deleted';
else StatusBar1.Panels[0].Text := 'Undetermined status';
end;
end;
end;
- Note: If a record’s
UpdateStatusisusModified, you can examine theOldValueproperty for each field in the dataset to determine its previous value.OldValueis meaningless for records withUpdateStatusvalues other thanusModified. For more information about examining and usingOldValue, see Creating an OnUpdateRecord Event Handler in the Delphi Developer’s Guide.