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

Printed data doubles the preview

edited April 2016 in General
Still using D7 and RB7 on this old project. I have a report with summary
data, using variables that are based on values calculated during report
generation (DetailBeforePrint). Actually the Detail Band itself is left
invisible since we only need the summary page in this report.

After much work to verify the data in the summary band is correct, I was
quite surprised when many of those values calculated on traversal were
doubled when printing the page from a preview. Data is correct on
Preview, OR on printing directly. BUT data is doubled for these
variables when doing a Print from the preview. Data is even tripled when
doing a Print and printing to a PDF.

Strange to me, but if I check the box Report-Cache Pages, the data is
stable on printing from preview. So, yes I did discover a fix, but I wonder:

- Should all reports with variables calculated in DetailBeforePrint have
the Cache Pages checked? or are there other situations too?

- I saw something about calling Report.Reset?

- is this something I need to do in other situations, or continue doing
as I develop reports in my updated RBuilder I will be using with Delphi
10 Seattle?

Scott Stalheim

Comments

  • edited April 2016
    Hi Scott,

    Do not make variable calculations in the DetailBand.BeforePrint. This
    event can fire multiple times per traversal which in turn can give
    incorrect results.

    When making calculations inside ReportBuilder, only use the
    TppVariable.OnCalc event. You can then use the variable timing to
    determine how often the OnCalc fires.

    Of course the best way to handle calculations for a report is to perform
    them outside the report in your database.

    See the following article on how to make calculations for a report.

    http://www.digital-metaphors.com/rbWiki/Delphi_Code/Calculations/Overview


    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited April 2016
    Thanks Nico,

    Works great! When programming in Delphi, I do most all on the data side.
    Forgot to mention this is in RAP for my end users, no opportunity to
    manipulate the data side. On one particular report I still have this
    nagging issue...

    Each detail band is essentially an observation which includes a
    prediction for the next observation. So in the each detail I calculate a
    global variable like:

    procedure Variable8OnCalc(var Value: variant);
    begin
    Value := Uppercase (Cow_Info['EndType']); {the PREDICTION!}
    EndStr:= Value;
    {EndStr is global used for Variable2 next line to see if prediction True}
    end;

    This works except at the top of a new page. I found a bit of a fix since
    the data is kind of grouped, and asking to keep the group together,
    preventing predictions from crossing pages - but I think I am missing
    something. Using variableOnCalc to calculate and hang on to globals not
    a good idea? better way?

    Thanks,
    Scott



  • edited April 2016
    Hi Scott,

    In addition to all calculations being done in the OnCalc event, all
    calculations should be done with TppVariable components as well.

    In your case, my guess is that you have a dynamic height detail band.
    In this instance, before the page breaks, ReportBuilder does not know if
    the detail band will fit and then needs to calculate the variable twice.
    The Variable itself will remain correct as we have some sophisticated
    logic in place to cache its value and roll back the calculation if a
    page break occurs. Your own separate calculations however can become
    out of sync.

    My suggestion is to use a separate Variable for your second calculation
    or try using static height detail bands. Also note that most of our
    calculation logic has been improved since RB 7. I also recommend
    upgrading to the latest version of the product to take advantage of
    these and many other improvements.

    Best Regards,

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