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)
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
maybe u have to disable the two-pass option (Report -> Options -> General)
greetz
Note: there are some cases where it is better to increment a variable in the obp of the memoview rather than the band.
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
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
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
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.
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
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.
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.
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.