rvico TRichView Reference | Tables

Undo/redo in Tables

Top  Previous  Next

Undo and Redo

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.

Example 1

Two operations: (inserting table and changing its color) will be undone in two steps

table := TRVTableItemInfo.CreateEx(4,3, RichViewEdit1.RVData);

if RichViewEdit1.InsertItem('', table) then

  table.Color := clRed;

Example 2

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

RichViewEdit1.InsertItem('', table);

About Using Non-Editor-Style Operations in Editor for Modifying Documents

(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.

if UndoLimit of editor = 0 (undo mechanism turned off). But Format must be called before calling any editor-style method.

After ClearUndo method. But Format must be called before calling any editor-style method.

Undo of Assignment to Properties

Assigning values to cell properties (and to VAlign property of rows) will not be undone.

But there are some special methods.

table.Cells[r,c].Color := clRed; // will not be undone

table.SetCellColor(clRed, r,c);  // will be undone.

(the complete list of these methods is below)

This was made because of efficiency reasons.

These methods do not update editor view. Use them together with BeginItemModify/EndItemModify.

For example

var item: TCustomRVItemInfo;

    table: TRVTableItemInfo;

    Data: Integer;

    rve: TCustomRichViewEdit;

    ItemNo: Integer;


  if not RichViewEdit1.CanChange or

     not RichViewEdit1.GetCurrentItemEx(TRVTableItemInfo, rve, item) then


  table := TRVTableItemInfo(item);

  ItemNo := rve.GetItemNo(table);

  rve.BeginItemModify(ItemNo, Data);

  table.SetRowVAlign(rvcBottom, 1);


  rve.EndItemModify(ItemNo, Data);



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:

SetCellColor, SetCellBorderColor, SetCellBorderLightColor;


SetCellBestWidth, SetCellBestHeight;

SetCellBackgroundImage, SetCellBackgroundImageFileName, SetCellBackgroundStyle;



TRichView © trichview.com