Example: dividing table

<< Click to display table of contents >>

Example: dividing table

function SplitTable(rve: TCustomRichViewEdit; table: TRVTableItemInfo;

  RowCountInFirstTable: Integer; PageBreak: Boolean): Boolean;

var r, c, mr, mc: Integer;

    newtable: TRVTableItemInfo;

    Stream: TMemoryStream;


  Result := False;

  if RowCountInFirstTable>=table.RowCount then


  for c := 0 to table.ColCount-1 do

    if table.Cells[RowCountInFirstTable, c] = nil then begin

      table.Rows.GetMainCell(RowCountInFirstTable, c, mr, mc);

      if mr<RowCountInFirstTable then



  Stream := TMemoryStream.Create;

  table.SaveRowsToStream(Stream, RowCountInFirstTable,


  Stream.Position := 0;

  newtable := TRVTableItemInfo.CreateEx(00, rve.RVData);


  if PageBreak then

    newtable.PageBreakBefore := True;





    table.DeleteRows(RowCountInFirstTable, table.RowCount-RowCountInFirstTable, True);

    // table.GetMyItemNo is the same as rve.GetItemNo(table), but faster

    rve.SetSelectionBounds(table.GetMyItemNo, 1, table.GetMyItemNo, 1);

    rve.InsertItem('', newtable);




  Result := True;



rve editor directly containing table;

table the table to divide.

These two parameters are usually a result of RichViewEdit1.GetCurrentItemEx.

The table will be divided into two tables.

The first resulting table will have row count = RowCountInFirstTable, the second table will have row count = table.RowCount-RowCountInFirstTable.

If PageBreak parameter is True, a page break will be inserted between tables.

Return value: True if the table was divided.

This is an editing operation, it can be undone and redone by the user.