Page# numbering

Hi to everyone

I have written a simple Onbefore event with code like

procedure PagememoOnBeforePrint(Sender: TfrxComponent);
begin
if GETLANGUAGE=0 then // a user defined function
Pagememo.text:=format('Σελίς %d από %d',[<Page#>,<TotalPages#>]) // Greek transalation
else
Pagememo.text:=format('Page %d of %d',[<Page#>,<TotalPages#>]) // English translation

end;

when the report is loaded the pagemo prints Page 1 of 0 or Σελίς 1 από 0

when no event assigned like Page [Page#] of [TotalPages#] on the page footer band,
prints Page 1 of 1 (exactly the total pages number)

Thanks Vagelis

Comments

  • edited 2:50AM
    When you want to do page numbering using the event/scripts, you need to set the Report.EngineOptions.DoublePass to true (it can be done by selecting the report in the report tree and by using the object inspector to change the properties.

    When DoublePass is set, the report will be printed twice... so you need to be careful about what you do in the code.

    This is the code that I use to do the page count. I put it on the page header :
    var
      InitDone: Boolean;
    
    procedure PageHeaderOnBeforePrint(Sender: TfrxComponent);
    begin
      if not InitDone then begin
        Report.Variables['CurrentPage'] := 0;
        Report.Variables['TotalPage'] := 0;        
      
        InitDone := True;                                  
      end;
    
      Report.Variables['CurrentPage'] := Report.Variables['CurrentPage'] + 1;
      if not Engine.FinalPass then begin                      
        Report.Variables['TotalPage'] := Report.Variables['TotalPage'] + 1;
      end;
    
      if <CurrentPage> > <TotalPage> then begin
        Report.Variables['CurrentPage'] := 1;                    
      end;
    
  • edited 2:50AM
    I forgot to clarify that the code above will always work (even in batch printing). Since in your example you are not printing in a batch, you could simply assign the text 'Page [Page#] of [TotalPages#]' to the MemoView in the start of the report. It should be working.
  • edited 2:50AM
    PatF wrote: »
    I forgot to clarify that the code above will always work (even in batch printing). Since in your example you are not printing in a batch, you could simply assign the text 'Page [Page#] of [TotalPages#]' to the MemoView in the start of the report. It should be working.
    Its seems working after declaring two pass report=true
    Thank you for your information


    * I have remark that a vertical line with property baRight on band its not working after installation of the last version (top is remaing 0.50 and not 0)
    Can you reproduce this

    Thanks Vagelis Bekyros

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.