not save the last page blank

General TRichView support forum. Please post your questions here
Post Reply
Ceprotec
Posts: 259
Joined: Thu Oct 28, 2010 6:09 pm
Contact:

not save the last page blank

Post by Ceprotec »

which command to use to position cursor in row 1 column 1 the last page of text?

After positioning the cursor, make a function to see if that page is blank or spaces to the end?

Objective: Do not allow the User save the text with the last page blank.
thanks
Sergey Tkachenko
Site Admin
Posts: 17253
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Do you use ScaleRichView, or TRichViewEdit+TRVPrint?
Ceprotec
Posts: 259
Joined: Thu Oct 28, 2010 6:09 pm
Contact:

Post by Ceprotec »

I use ScaleRichView
Sergey Tkachenko
Site Admin
Posts: 17253
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

In ScaleRichView, you can simply call

Code: Select all

  SRichViewEdit1.CurrentPage := SRichViewEdit1.PageCount;
This code moves the caret to the beginning of the last page.


This procedure removes all spaces and tabs at the end of the document:

Code: Select all

procedure TrimBottom(SRichViewEdit1: TSRichViewEdit);
var i, ItemNo: Integer;
    Edit: TCustomRichViewEdit;
begin
  ItemNo := -1;
  Edit := SRichViewEdit1.RichViewEdit;
  // deleting empty items at the end of the document
  for i := Edit.ItemCount-1 downto 1 do
    if ((Edit.GetItemStyle(i)<0) and (Edit.GetItemStyle(i)<>rvsTab)) or
       ((Edit.GetItemStyle(i)>=0) and (Trim(Edit.GetItemText(i))<>'')) then begin
      ItemNo := i;
      break;
    end;
  if ItemNo<0 then
    exit;
  if Edit.GetItemStyle(ItemNo)=rvsListMarker then
    inc(ItemNo);
  inc(ItemNo);
  Edit.DeleteItems(ItemNo, Edit.ItemCount-ItemNo);
  // removing spaces from the end of the last text item
  ItemNo := Edit.ItemCount-1;
  if Edit.GetItemStyle(ItemNo)>=0 then
    Edit.SetItemText(ItemNo, TrimRight(Edit.GetItemText(ItemNo)));
  Edit.Format;
  Edit.ClearUndo;
end;
This procedure cannot be undone. If you want a similar procedure as an undoable editing operation, let me know.
Post Reply