RAD Studio |  |

Indicating What Records Are Modified
See Also
Collapse All

While the user edits a client dataset, you may find it useful to provide feedback about the edits that have been made. This is especially useful if you want to allow the user to undo specific edits, for example, by navigating to them and clicking an "Undo" button.

The UpdateStatus method and StatusFilter properties are useful when providing feedback on what updates have occurred:

UpdateStatus indicates what type of update, if any, has occurred for the current record. It can be any of the following values:

- usUnmodified indicates that the current record is unchanged.
- usModified indicates that the current record has been edited.
- usInserted indicates a record that was inserted by the user.
- usDeleted indicates a record that was deleted by the user.

StatusFilter controls what type of updates in the change log are visible. StatusFilter works on cached records in much the same way as filters work on regular data. StatusFilter is a set, so it can contain any combination of the following values:

- usUnmodified indicates an unmodified record.
- usModified indicates a modified record.
- usInserted indicates an inserted record.
- usDeleted indicates a deleted record.

By default, StatusFilter is the set [usModified, usInserted, usUnmodified]. You can add usDeleted to this set to provide feedback about deleted records as well.
Note: UpdateStatus and StatusFilter are also useful in BeforeUpdateRecord and OnReconcileError event handlers. For information about BeforeUpdateRecord, see Intervening as updates are applied For information about OnReconcileError, see Reconciling Update Errors.
The following example shows how to provide feedback about the update status of records using the UpdateStatus method. It assumes that you have changed the StatusFilter property to include usDeleted, allowing deleted records to remain visible in the dataset. It further assumes that you have added a calculated field to the dataset called "Status."
Copy Code

    procedure TForm1.ClientDataSet1CalcFields(DataSet: TDataSet);
    begin
      with ClientDataSet1 do begin
        case UpdateStatus of
          usUnmodified: FieldByName('Status').AsString := '';
          usModified: FieldByName('Status').AsString := 'M';
          usInserted: FieldByName('Status').AsString := 'I';
          usDeleted: FieldByName('Status').AsString := 'D';
        end;
      end;
    end;

Copy Code

    void __fastcall TForm1::ClientDataSet1CalcFields(TDataSet *DataSet)
    {
      switch (DataSet->UpdateStatus())
      {
        case usUnmodified:
          ClientDataSet1Status->Value = NULL; break;
        case usModified:
          ClientDataSet1Status->Value = "M"; break;
        case usInserted:
          ClientDataSet1Status->Value = "I"; break;
        case usDeleted:
          ClientDataSet1Status->Value = "D"; break;
      }
    }

See Also

Overview of Using Cached Updates

Updating Records

Choosing the Type of Dataset for Caching Updates

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!