Checking Update Status

From InterBase

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:

Return values for UpdateStatus
Value Meaning

usUnmodified

Record is unchanged

usModified

Record is changed

usInserted

Record is a new record

usDeleted

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 UpdateStatus is usModified, you can examine the OldValue property for each field in the dataset to determine its previous value. OldValue is meaningless for records with UpdateStatus values other than usModified. For more information about examining and using OldValue, see Creating an OnUpdateRecord Event Handler in the Delphi Developer’s Guide.

Advance To: