trichview.com Forum Index trichview.com
TRichView support forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

[Example] Dividing table

 
Post new topic   Reply to topic    trichview.com Forum Index -> Examples, Demos
View previous topic :: View next topic  
Author Message
Sergey Tkachenko
Site Admin


Joined: 27 Aug 2005
Posts: 6576

PostPosted: Mon Jan 30, 2006 7:21 pm    Post subject: [Example] Dividing table Reply with quote

Code:
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.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    trichview.com Forum Index -> Examples, Demos All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group