Home Subreports

OnCalc Event question.

edited March 2004 in Subreports
Hi,

I have a report with 4 subreports embedded. Each sub report is linked to a
seperate TDataset - and at the end of the subreport, it has a tppDBCalc
component that adds up the total amount for that sub report.

At the end of the report, I have a TppVariable field that I want to equal
the total amount of the 4 subreports. (An overall total field).

To do this, I have placed code in the OnCalc event of each tppDBCalc
components like so:

ppvariable1.value := ppvariable1.value + ppdbcalc1.Value;
(Replacing ppdbcalc1 with 2, 3 or 4 as required).

The problem that I have is that the OnCalc event appears to be triggered for
each record within the subreport - and the calculations are wrong.

For example, lets say that SubReport1 has the following:

Box of Tissues $2.00
9v Batteries $3.00
Widgets $8.00

The OnCalc event will fire, with the .value being $2.00. It will then fire
again, with the value being $5.00, and finally fire once more, with the
value being $13.00. The last amount is the correct total - which it
displays, but the problem I'm having is that it is triggering the OnCalc
event every time it goes to add a value to itself, so in the end, my
ppvariable1 will return the value $20.00

Am I going about this the correct way - or is their a setting I have missed?

Thanks & Regards

Adam Hair.

Comments

  • edited March 2004

    For calculations such as this I would try using all TppVariables. Then in
    the subreport variable OnCalc's you could code something like this:

    mySubVariable.Value := mySubVariable.Value + plOrder['AmountPaid'];
    myTotalVariable.Value := myTotalVariable.Value + plOrder['AmountPaid'];




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

    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
  • edited March 2004
    Hi Nard,

    Thanks for the idea.

    I got around this problem by still using the TotalVarable oncalc event, but
    instead of adding off the totalvariable.value, I looked straight at the
    dataset, and added off that.

    ie:

    procedure TReportInvoiceSummary.ppDBCalc4Calc(Sender: TObject);
    begin
    //ppvariable1.value := ppvariable1.value + ppdbcalc4.Value; {What it used
    to be}
    ppVariable1.value := priceround(ppVariable1.value + MiscQAmount.value);
    end;

    Is their no event that triggers only once, each time a ppdbcalc event
    prints? (ie, not when it's doing it's additoin?)

    Thanks & Regards

    Adam.
  • edited March 2004

    Great.

    If you want to see how events fire visually, you can run the
    RBuilder\Demos\Reports\Demo.dpr app and select the Events section. There a
    some event-tracker demos that show events as they fire. You can make your
    own event-tracker demos by using the same techniques used to create these
    demos.



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

    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
This discussion has been closed.