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

Possible bug with ReportBuilder 10.02 Enterpsise with Delphi 7

edited March 2008 in Devices
In one of our reports, using ReportBuilder, there is some calculations
made inside the event BeforeGenerate of a Detail band.

The result of this calculation is showed on screen correctly. But, when we
print this report, the value appears doubled on paper.

Debugging the application we found that the event BeforeGenerate is called
*at least* one time before the report is shown on screen and right before
the report is about to be printed. Thus, giving us the doubled (and
incorrect) result.

Is this the normal behavior of the component? Should this particular event
be called "twice"?

If this is the case, we will have to redo most of our reports because we
have many calculations in these events.

Thanks in advance.



--- posted by geoForum on http://delphi.newswhat.com

Comments

  • edited March 2008
    "bernardolopes" wrote in message
  • edited March 2008
    >The BeforeGenerate event is risky for calcs because it is subject to other
    Thanks for your answer Paul, but I'm afraid I don't quite follow you.

    I couldn't find any mention to those timing events that you talked about
    in the component TppReport, nor in other components of the RBuilder tab
    that I looked.

    Would care to elaborate more on the subject please?

    Nonetheless I saw another event that maybe could hold some calculations
    reliably, the OnStartFirstPass event. Then I did a search here in the
    Mailing List and found that someone also have had trouble regarding the
    event "double-firing" execution.



    --- posted by geoForum on http://delphi.newswhat.com
  • edited March 2008
    Hi Bernard,

    Calculations inside a report should primarilly be made in the OnCalc event
    of a TppVariable. If you must make a calculation elsewhere, you will need
    to take into account that the event may fire more than once. There is no
    way to be sure any other events will only fire once per iteration in
    ReportBuilder.

    ----------------------------------------------------------------------
    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
  • edited March 2008
    "bernardolopes" wrote in message
  • edited March 2008
    Thank you very much for the explanations, Nico.

    Following your tips we managed to get our calcs right and to understand
    the machanics of ReportBuilder.

    We were definitely wrong using the band's events to do our math. We got
    this bad habit from another reporting component.

    Thank you again and congratulations for your solid product. We'll surely
    mention it to other softhouses that we are partner of.

    -Bernardo Lopes



    --- posted by geoForum on http://delphi.newswhat.com
This discussion has been closed.