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

BeforePrint executing on each page. PDF Doesn't

edited November 2003 in Server
I have a discrepancy between my viewer and pdf file that I generate through
pragnaan.

In my BeforePrint script I set the global variable g_sumgiving to zero. I
run the report. With each record g_sumgiving is incremented the appropriate
dollar value. At the end of the report the value of g_sumgiving is only the
sum of the records on the last page. Not all the records. BeforePrint seems
to be executing on each page.

I then press my PDF button at the top and go to the last page and the value
for g_sumgiving is correct. It worked correctly in the PDF file.
BeforePrint seems to only be executing before generation of the report when
going to a PDF.

I then decided to move my initialization of the g_sumgiving variable to the
BeforeGenerate script. This caused the viewer to print correctly on the
last page. I then pressed my PDF button and g_sumgiving was doubled.
Apparently the BeforeGenerate wasn't executed with the PDF button.

Any Suggestions?

My Report is set up with Addresses and items with dollar values. The report
detail band is set to invisible. It has a groupfooterband that shows the sum
of the items. The groupfooterband has a Region that checks whether or not
the band should be visible or not depending on other globals. Those all
seem to work.

Bill Gifford

Comments

  • edited November 2003

    Use TppVariables to perform all calculations. Do not use global variables.

    --
    Nard Moseley
    Digital Metaphors
    http://www.digital-metaphors.com

    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
  • edited November 2003
    I'm not quite sure how this fixes my problem. A TppVariable is declared at
    the top of the datamodule while I'm declaring my global variables in the
    private section of the datamodule. How does the variable type make a
    difference?

    Here is an example of my problem.

    John Anderson has three entries of $10, $10, $10
    Mary Smith has 4 entries $20,$20,$20,$20

    I only want to display people who gave a total of more than $50. I created
    a groupsection that breaks on the persons id value. The body exists but is
    set to invisible. My TppVariable calculation in the body runs three times
    for John Anderson setting g_PERSONgiving to ($10 first pass) , ($20 second
    pass), ($30 for the final pass). I then have a TppVariable in the
    GroupFooter that checks the g_PERSONgiving and verifies that it is less than
    $50 so it sets the visible property to No and the g_SUMgiving is not
    increased. I then clear g_PERSONgiving and go to Mary Smith and do the same
    thing. In the group footer it sees that she is over $50 and sets visible to
    true and adds the $80 to g_SUMGiving. Everything works except g_SUMgiving
    gets set to zero at the top of each page because of the BeforePrint script
    executing at the top of each page while the PDF doesn't.

    Is there a way to tell if your on the first page in the BeforePrint script?
    That way I could set the variable on the first page and not re-initialize
    the variables on the rest.


  • edited November 2003

    Below is a tech tip on performing calculations.

    For the calculations you describe, you will want to configure the
    TppVariable to reset when the group ends. Press the right mouse button over
    the TppVariable and select the Timing... menu option to display the timing
    dialog. The Calc timing is almost always the default. The Reset timing in
    this case should the group.

    The TppVariable has alot of built-in functionality to deal with the
    complexities of the report generation process. The TppVariable.OnCalc event
    is designed to fire at the appropriate time. The TppVariable can be
    configured to reset itself when a group breaks, etc. The TppVariable has the
    ability to cache its intermediate results as of the start of each page and
    then restore these results when the page generates.

    An alternative approach to this report would be to create summary query that
    performs the summary calculations for each person.


    ------------------------------------------------------------------------
    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.



    --
    Tech Support mailto:support@digital-metaphors.com
    Digital Metaphors http://www.digital-metaphors.com




    --
    Nard Moseley
    Digital Metaphors
    http://www.digital-metaphors.com

    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
  • edited November 2003
    Thanks. I haven't had the chance to try it but it looks like it is exactly
    what I need.

This discussion has been closed.