RAD Studio |  |

Undoing Changes
See Also
Collapse All

Even though a record's original version remains unchanged in Data, each time a user edits a record, leaves it, and returns to it, the user sees the last changed version of the record. If a user or application edits a record a number of times, each changed version of the record is stored in the change log as a separate entry.

Storing each change to a record makes it possible to support multiple levels of undo operations should it be necessary to restore a record's previous state:

- To remove the last change to a record, call UndoLastChange. UndoLastChange takes a Boolean parameter, FollowChange, that indicates whether to reposition the cursor on the restored record (True), or to leave the cursor on the current record (False). If there are several changes to a record, each call to UndoLastChange removes another layer of edits. UndoLastChange returns a Boolean value indicating success or failure. If the removal occurs, UndoLastChange returns True. Use the ChangeCount property to check whether there are more changes to undo. ChangeCount indicates the number of changes stored in the change log.
- Instead of removing each layer of changes to a single record, you can remove them all at once. To remove all changes to a record, select the record, and call RevertRecord. RevertRecord removes any changes to the current record from the change log.
- To restore a deleted record, first set the StatusFilter property to [usDeleted], which makes the deleted records "visible." Next, navigate to the record you want to restore and call RevertRecord. Finally, restore the StatusFilter property to [usModified, usInserted, usUnmodified] so that the edited version of the dataset (now containing the restored record) is again visible.
- At any point during edits, you can save the current state of the change log using the SavePoint property. Reading SavePoint returns a marker into the current position in the change log. Later, if you want to undo all changes that occurred since you read the save point, set SavePoint to the value you read previously. Your application can obtain values for multiple save points. However, once you back up the change log to a save point, the values of all save points that your application read after that one are invalid.
- You can abandon all changes recorded in the change log by calling CancelUpdates. CancelUpdates clears the change log, effectively discarding all edits to all records. Be careful when you call CancelUpdates. After you call CancelUpdates, you cannot recover any changes that were in the log.

See Also

Saving Changes

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