OnBeforePrint called several times ?!?

Hi,
I have a report with the script calculating a running total inside band's OnBeforePrint.
Everything runs fine until sometimes, the band's OBP is called twice. This happens at the bottom of some pages (depending on layout).

I found out by declaring a variable, increment it in OBP and printing it on the page : for some pages, the counter misses one number : the band was not printed (because not enough space left) but the OBP was called again after the NewPage().

I have tried to reproduce the bug on a simple report but it doesn't show up ; this bug is very tight to the layout.

What can I do/look now ? I can post the .FR3 but would it help ?

Thanks for your help (BTW I use FR4.12 on D2010 on XP)

Comments

  • edited 9:27AM
    Hello,

    maybe u have to disable the two-pass option (Report -> Options -> General)

    greetz
  • gordkgordk St.Catherines On. Canada.
    edited 9:27AM
    i would like to see the code from the reports code page. Also where is the memo located that you are printing the variable value? ie which band?
    Note: there are some cases where it is better to increment a variable in the obp of the memoview rather than the band.
  • edited 9:27AM
    maybe u have to disable the two-pass option (Report -> Options -> General)

    1) I didn't say all amounts were doubled, only some of them who are at the limit of 2 pages (so hard to find the culprit, believe me)
    2) I tried calculating the total only when Engine.FinalPass which doesn't help
  • edited 9:27AM
    gordk wrote: »
    i would like to see the code from the reports code page.

    This is the relevant code.
    - totphono is the running total
    - The variable "ligne" helped me see the OBP was called twice for some records.
    - The frxMVEN.idtmpven / lastligne is a serialization (workaround) I added to make sure my total was counted only once
    procedure MasterData2OnBeforePrint(Sender: TfrxComponent);
    begin
      ligne:=ligne+1;
      with MasterData2, Engine do
      begin
        if <frxMVEN."idtmpven"> <> lastLigne then begin                                                       
          totphono:=totphono+<frxMVEN."brutad">;
          // other calculations not involving totphono
          lastligne:=<frxMVEN."idtmpven">;
        end;
      end
    end;
    
    gordk wrote: »
    Also where is the memo located that you are printing the variable value? ie which band?

    The report is a little complex, I will try to make it clear how it's supposed to work :

    Main report contains :
    - MasterBand1
    - DetailBand1 (contains subreport1 and only subreport1)
    - totphono is reset to zero in DetailBand1's OBP
    - Child2 (child of DetailBand1) : this is where the "totphono" value is printed

    SubReport1 contains :
    - GroupHeader1 based on DetailBand1's datasource (printed when DB1 changes)
    - GroupHeader3 based on MasterData2's datasource
    - MasterData2 : his OBP is called twice sometimes
    - Child1 linked to MasterData2, only printed when report is in "debug" mode (prints more details). Since this changes the layout, it also changes the total.
    - GroupFooter3 (no totals printed but stretchable because text can be long)
    - Child14 linked to GroupFooter3 : just a horizontalline that must be printed underneath GF3
    - GroupFooter1 (counterpart of GroupHeader1). This prints a sum(<frxMVEN."brutad">) which is correct (and how I found the bug)

    If I print "totphono" on the MasterData2 line, I see the running total and on top of "some"pages, I can see that the last value has been added twice
    gordk wrote: »
    Note: there are some cases where it is better to increment a variable in the obp of the memoview rather than the band.

    Also tried this but didn't help, the memo's OBP is called twice also.

    Let me know if you want me to send you the .FR3 or a PDF demonstrating the bug.
  • gordkgordk St.Catherines On. Canada.
    edited 9:27AM
    yes zip up the .fr3 and also a .fp3 of the output.
    the culprit seems to be about here
    - MasterData2 : his OBP is called twice sometimes
  • edited 9:27AM
    gordk wrote: »
    yes zip up the .fr3 and also a .fp3 of the output.
    Attached.
    gordk wrote: »
    the culprit seems to be about here
    - MasterData2 : his OBP is called twice sometimes
    100% agree ;-)

    I added yellow-background fields to demonstrate the problem. From left to right :
    - unique identifier (frxMVEN."idtmpven")
    - running total
    - "ligne" (number of times MasterData2's OBP has been called)

    I have disabled, of course, the unique identifier check code.

    The best place to see the bug is at the top of page 5 :
    - running total = 17,15 on line 148 (end of page 4)
    - the value added (rightmost) should be 0,17 so running total should be 17,15+0,17=17,32 but it's 17,15+(2*0,17)=17,49
    - on page 5 you see 19,64 as subtotal which is correct (calculated by FR's aggregate) and "Total pour l'album = 19,82" : the wrong total
  • gpigpi
    edited 9:27AM
    Try
    procedure MasterData2OnBeforePrint(Sender: TfrxComponent);
    begin
      if not Engine.SecondScriptCall then ligne:=ligne+1;
      with MasterData2, Engine do
      begin
        if <frxMVEN."idtmpven"> <> lastLigne then begin                                                      
          if not Engine.SecondScriptCall then totphono:=totphono+<frxMVEN."brutad">;
          // other calculations not involving totphono
          lastligne:=<frxMVEN."idtmpven">;
        end;
      end
    end;
    
  • edited 9:27AM
    gpi wrote: »
    Try
          if not Engine.SecondScriptCall then totphono:=totphono+<frxMVEN."brutad">;
    

    It works but should this be considered "normal behaviour" or workaround ? In the former case, it would be a nice idea to add something like this :
    "in some cases the event can be called repeatedly during grouping. To determine if this is the case, see Engine.SecondScriptCall"
    to the "Events" chapter of the documentation.

    Thanks for your help.
  • gordkgordk St.Catherines On. Canada.
    edited 9:27AM
    some times Ie miss the easy things
    on looking at your code i realized this was a report converted from fr2 to fr4.
    try to doing your incrementing in the onafterprint event.
  • edited 9:27AM
    gordk wrote: »
    try to doing your incrementing in the onafterprint event.
    I tried that but it was still called twice. And that would mean : impossible to print (script-calculated) running totals (because calculated afterwards)...

    It would be nice to have a special event (in "Data"-bands : TfrxMasterData, TfrxDetailData, etc.) called only once per row of data : THE place where to do computations whereas other events are more dedicated to appearance (in my vision).

    At least, please add a warning to the documentation of "events" about the possibility of the event to be called twice and the way to workaround it : Engine.SecondScriptCall.

    Thanks for your help.

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.