Home Subreports

First pass events fire more than once in subreport

edited August 2003 in Subreports
I have a report with event handlers in the OnStartFirstPass and
OnEndFirstPass. I update some variables in my app and I want these to run
only once. The report works by itself (I have put ShowMessages) but when it
is used as a dynamically loaded subreport (section type) the above events
fire more than once. Both the original report as well as the "containing"
report are 2 pass reports.
I use a global var in the original report to control the execution of the 2
events and it works but there must be something that I am mising.
I tried the Report.FirstPass variable but it does don work (well if it did
the events would not fire more than once in the first place).
Also I thought that the Report events don't work when it is used as
subreport (I get the message that it cannot load the events for the
Before/After print events of a child report - which is resonable. Why then
the OnStartFirstPass/OnEndFirstPass event handlers of a child report work ?

Thanks

Yannis

Comments

  • edited August 2003
    Hi Yannis,

    The dynamic subreport loading demo is atypical. It loads a report template
    after the main report has begun generating. This is problably why the events
    fires twice because it has to be initialized for the new template which it
    loads. You'll have to code a boolean flag in your event handlers in order
    to determine if you've set your app's variables previously when you are
    printing a report which has dynamic subreport loading involved.


    Cheers,

    Jim Bennett
    Digital Metaphors


  • edited August 2003
    Thank you Jim.
    I have already used a var to control the execution of the event handlers.
    However in a report with a normal subreport the OnFirstPass event of the
    subreport is called twice - no dynamic loading here.
    I have build a trivial app just a report with a label and a subreport with
    another label (bith in the title bands). In the subreport's OnStartFirstPass
    I have a ShowMessage. This is displayed twice when I preview. On the
    contrary the main report's OnStartFirstPass event is called only once.
    Any ideas?

    Yannis



  • edited August 2003
    Hi Yannis, you're right it does get fired twice even on a simple report with
    a subreport. The engine is being initialized in two cases because it appears
    that it how it has to work. It fires when the main report begins generating
    for the first time and then it fires the event again because each subreport
    gets a chance to generate multiple times, so it fires the event again. There
    is no optimization in place at this time for this case when the first
    subreport goes to print to have the event fire only once.


    Cheers,

    Jim Bennett
    Digital Metaphors


This discussion has been closed.