[Example] How to insert a blank page

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

[Example] How to insert a blank page

Post by Sergey Tkachenko »

The procedure below inserts a new empty page at the caret position.
(it implements it by adding an empty line and up to two page breaks)

Code: Select all

procedure InsertPage(rve: TCustomRichViewEdit);
var
  AtStart, AtEnd: Boolean;
begin
  rve := rve.TopLevelEditor;
  AtStart :=
    ((rve.CurItemNo = 0) or
     ((rve.CurItemNo = 1) and (rve.GetItemStyle(0) = rvsListMarker))) and
    (rve.OffsetInCurItem <= rve.GetOffsBeforeItem(rve.CurItemNo));
  AtEnd := (rve.CurItemNo = rve.ItemCount - 1) and
    (rve.OffsetInCurItem >= rve.GetOffsAfterItem(rve.CurItemNo));
  rve.BeginUndoGroup(rvutInsertPageBreak);
  rve.SetUndoGroupMode(True);
  try
    rve.InsertText(#13);
    rve.InsertPageBreak;
    if not AtEnd then
    begin
      SendMessage(rve.Handle, WM_KEYDOWN, VK_LEFT, 0);
      if not AtStart then
        rve.InsertPageBreak;
    end;
  finally
    rve.SetUndoGroupMode(False);
  end;
end;
How to use in ScaleRichView:

Code: Select all

procedure TForm3.ToolButton63Click(Sender: TObject);
begin
  SRichViewEdit1.StartEditing(srvrveMain);
  SRichViewEdit1.CanUpdate := False;
  InsertPage(SRichViewEdit1.ActiveEditor);
  SRichViewEdit1.CanUpdate := True;
end;
Post Reply