Undo/redo in Tables
All table operations (adding/deleting rows, merging/unmerging, assignment of table properties) can be undone/redone if table was inserted into RichViewEdit.
Operations will not be undone if:
▪table was created, but not inserted yet;
▪table was inserted in RichView;
▪table was inserted in RichViewEdit with UndoLimit=0.
Two operations: (inserting table and changing its color) will be undone in two steps
if RichViewEdit1.InsertItem('', table) then
table.Color := clRed;
One operation (inserting red table) will be undone in one step
table := TRVTableItemInfo.CreateEx(4,3, RichViewEdit1.RVData);
table.Color := clRed; // table is not inserted yet
(AddNL, for example)
These methods must not be mixed with editor-style methods (such as InsertText) because they will conflict with undo mechanism. Result of undo-redo operations is unpredictable if non-editor operations were used after editor-style one.
This rule relates not only to contents of the main document, but to cells also.
There are some cases when non-editor-style methods may be useful in editor:
▪After Clear method, before any editor-style methods (for generating a document before editing). Clear method clears undo and redo buffers.
▪In table cells before inserting a table.
Assigning values to cell properties (and to VAlign property of rows) will not be undone.
But there are some special methods.
table.SetCellColor(clRed, r,c); // will be undone.
(the complete list of these methods is below)
This was made because of efficiency reasons.
var item: TCustomRVItemInfo;
if not RichViewEdit1.CanChange or
not RichViewEdit1.GetCurrentItemEx(TRVTableItemInfo, rve, item) then
table := TRVTableItemInfo(item);
ItemNo := rve.GetItemNo(table);
Assignments to all table properties can be undone (but still the sequence BeginItemModify-operations-EndItemModify-Change is required). The only exception is VisibleBorders property, use SetTableVisibleBorders if you want to implement an undoable operation.
Direct assignment to cells and rows properties cannot be undone, so use the methods below to implement an undoable operation.
Methods for assigning table properties:
Methods for assigning row properties:
Methods for assigning cell properties: