Home General
New Blog Posts: Merging Reports - Part 1 and Part 2

Before Generate Problem in Ver 7.03

edited March 2005 in General
HI ,

I am have a problem with some thing that has never been a problem before, in
that I need to add up a series of subtotals in a report that spans many
pages, and have always in the past used the before generate evened for the
band to do the actual adding up, as I though this event only fired ONCE for
each time the band was built for each line: my reasoning being: -

Declaration

property BeforeGenerate: TNotifyEvent;

Description

The BeforeGenerate event fires before the band prints. Use the
BeforeGenerate event when you want to perform actions before a band prints.
BeforeGenerate differs from BeforePrint in that BeforePrint fires every time
a band has the opportunity to print. Sometimes the band has an opportunity
to print, but for various reasons does not (usually printing on the next
page instead.) In these cases, BeforePrint will fire, but BeforeGenerate
will not.

where thinking that "but BeforeGenerate will not." meant once for each row
in the dataset, it appears in my report that has a single band and is filled
by a single region (So I can make a short report by making it not visible,
but still using the beforegenerate event to do the calcs), fires twice, once
to see if it can fit it on the bottom of the first page and then AGAIN when
it places it on the top of page two.

How do I correct this in Version 7.03 ?

Very cheesed off, cause I know its my fault somehow and I just cant see it.

Thanks
Colin Coleman

Comments

  • edited March 2005
    Hi Colin,

    Whenever making calculations in ReportBuilder it is recommended that you use
    the OnCalc event of a TppVariable. This event is the only event in RB that
    is gaurenteed to fire only once per traversal as a page/group breaks. See
    the following article for more information.

    ----------------------------------------------------------------------
    TECH TIP: Performing Calculations
    ----------------------------------------------------------------------

    Calculations can be done either on the data access side or within
    ReportBuilder.

    When designing reports there are always decisions to be made as to how much
    processing to do on the data side versus the report side. Usually doing more
    on one side can greatly simplify the other. So it is often a personal choice
    based on the power and flexibility of the data and report tools being used.


    DataAccess
    ----------

    a. Use SQL - using SQL you can perform many common calculations:

    example: Select FirstName + ' ' + LastName As FullName,
    Quantity * Price AS Cost,


    b. Delphi TDataSets enable you to create a calculated TField object and use
    the DataSet.OnCalcFields event

    c. Perform any amount of data processing, summarizing, massaging etc. to
    build a result set (query or temp table) to feed to the report.


    ReportBuilder
    -------------

    Calculations in ReportBuilder are performed primarily using the TppVariable
    component.

    a. Set the Variable.DataType

    b. Code the calculations using the Variable.OnCalc event.

    c. Use the Timing dialog to control the timing of the OnCalc event. To
    access the Timing dialog, right click over the Variable component and select
    the Timing... option from the speed menu.

    d. Set the LookAhead property to True, when you need to display summary
    calculations in the title, header, group header, etc.

    e. To perform calculations based on the results of other calculations use
    the Calc Order dialog of the band. To access the Calc Order dialog, right
    click over the Band component and select the Calc Order... option from the
    speed menu.


    By using TppVariable components ReportBuilder will take care of caching
    intermediate results of accumlated calcs that cross pages.

    There are a number of calculation examples in the main demos.dpr project.

    ---

    Additional Notes:

    1. Do NOT use Band.BeforePrint or Band.AfterPrint. These events fire
    multiple times and therefore should not be used for calculations.

    2. Do NOT store results in variables that exist outside of the reports. For
    example - form level variables.


    --
    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
This discussion has been closed.