[Example] Dividing table

Demos, code samples. Only questions related to the existing topics are allowed here.
Post Reply
Sergey Tkachenko
Site Admin
Posts: 13026
Joined: Sat Aug 27, 2005 10:28 am
Contact:

[Example] Dividing table

Post by Sergey Tkachenko » Mon Jan 30, 2006 7:21 pm

Code: Select all

function SplitTable(rve: TCustomRichViewEdit; table: TRVTableItemInfo;
  RowCountInFirstTable: Integer; PageBreak: Boolean): Boolean;
var r, c, mr, mc: Integer;
    newtable: TRVTableItemInfo;
    Stream: TMemoryStream;
begin
  Result := False;
  if RowCountInFirstTable>=table.Rows.Count then
    exit;
  for c := 0 to table.Rows[0].Count-1 do
    if table.Cells[RowCountInFirstTable, c]=nil then begin
      table.Rows.GetMainCell(RowCountInFirstTable, c, mr, mc);
      if mr<RowCountInFirstTable then
        exit;
    end;
  Stream := TMemoryStream.Create;
  table.SaveRowsToStream(Stream, RowCountInFirstTable,
    table.Rows.Count-RowCountInFirstTable);
  Stream.Position := 0;
  newtable := TRVTableItemInfo.CreateEx(0, 0, rve.RVData);
  newtable.LoadFromStream(Stream);
  if PageBreak then
    newtable.PageBreakBefore := True;
  Stream.Free;
  rve.BeginUndoGroup(rvutModifyItem);
  rve.SetUndoGroupMode(True);
  try
    table.DeleteRows(RowCountInFirstTable, table.Rows.Count-RowCountInFirstTable, True);
    rve.SetSelectionBounds(table.GetMyItemNo, 1, table.GetMyItemNo, 1);
    rve.InsertItem('', newtable);
  finally
    rve.SetUndoGroupMode(False);
  end;
  Result := True;
end;
Parameters:
rve - editor containing table;
table - the table to split
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.Rows.Count-RowCountInFirstTable.

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

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

Sergey Tkachenko
Site Admin
Posts: 13026
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko » Sat Oct 01, 2011 7:04 am

Since version 3.4, RichViewActions use a similar procedure for TrvActionTableSplit (menu Table | Split Table)

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 3 guests