Insert Item into a Header\Footer

General TRichView support forum. Please post your questions here
Post Reply
salexn75
Posts: 5
Joined: Thu Jul 15, 2010 9:07 am

Insert Item into a Header\Footer

Post by salexn75 »

Hi!
I have several questions:
1) I want to insert the page number into the Header or Footer. I did the same as the action
procedure TPageNoSetupForm.btnOkClick(Sender: TObject);
var
Item: TRVPageNumberItemInfo;
rve: TCustomRichViewEdit;
begin
fScaleRichView.PageProperty.PageNoFromNumber := ePageNo.Value;
rve := fScaleRichView.RVHeader.GetRootEditor;
Item := TRVPageNumberItemInfo.Create(rve.RVData);
Item.NumberType := rvpntDecimal;
rve.InsertItem('', Item);
end;

The number appears but when I double-click on the Header it disappears. What's wrong with my code?

2) Is it possible to show the page number from the second page?

3) Can you provide an example of how to change the alignment of the item: left, center and right?

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

Re: Insert Item into a Header\Footer

Post by Sergey Tkachenko »

1) Before inserting content to the footer, you must activate its editing using StartEditing(srvrveHeader);.
See the explanation here: https://www.trichview.com/forums/viewto ... 203#p39203
Sergey Tkachenko
Site Admin
Posts: 17553
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Insert Item into a Header\Footer

Post by Sergey Tkachenko »

2) To insert a page number from the second page, you need to activate the special header for the first page:
fScaleRichView.PageProperty.TitlePage := True.
(or, if you want to do it as an undoable operation, fScaleRichView..SetIntPropertyEd(srvipPPTitlePage, 1)).

Please note that fScaleRichView.StartEditing(srvrveHeader) activates editing heading on the current page.
So, if you call it when the caret is in the first page, it will activate editing of the first page header.
So, if you call it when the caret is in the second or subsequent page, it will activate editing of normal heading (note: it is also possible to have different heading for odd and even pages).

There is an alternative to modifying headers as an editing operations.
Instead, you can modify fScaleRichView.SubDocuments[srvhftNormalHeader], then call fScaleRichView.Format;
This modification must be made when the header is not being edited.
Sergey Tkachenko
Site Admin
Posts: 17553
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Insert Item into a Header\Footer

Post by Sergey Tkachenko »

3)

This function returns the index of paragraph style having all properties of the ParaNo-th paragraph style, but the specified alignment.
If such a style does not exist, the function creates it:

Code: Select all

function GetParaNoWithAlignment(ARVStyle: TRVStyle; ParaNo: Integer;
  Alignment: TRVAlignment): Integer;
var
  ParaStyle: TParaInfo;
begin
  if ARVStyle.ParaStyles[ParaNo].Alignment = Alignment then
  begin
    Result := ParaNo;
    exit;
  end;
  ParaStyle := TParaInfo.Create(nil);
  ParaStyle.Assign(ARVStyle.ParaStyles[ParaNo]);
  ParaStyle.Alignment := Alignment;
  Result := ARVStyle.FindParaStyle(ParaStyle);
  ParaStyle.Free;
end;
Inserting page number and then applying centering:

Code: Select all

procedure TPageNoSetupForm.btnOkClick(Sender: TObject);
var
  Item: TRVPageNumberItemInfo;
  rve: TCustomRichViewEdit;
begin
  fScaleRichView.PageProperty.PageNoFromNumber := ePageNo.Value;
  fScaleRichView.StartEditing(srvrveHeader);
  rve := fScaleRichView.RVHeader.GetRootEditor;
  Item := TRVPageNumberItemInfo.Create(rve.RVData);
  Item.NumberType := rvpntDecimal;
  rve.InsertItem('', Item);
  rve.ApplyParaStyle(GetParaNoWithAlignment(rve.Style, rve.CurParaStyleNo, rvaCenter));
end;
Post Reply