- use the TppVariable.OnCalc event to perform calculations. Do not use DetailBand before print. See the Developers Guide Tutorials and the Calculations thread of the Tech Tips newsgroups. Here is a quick overview...
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.
-- Nard Moseley Digital Metaphors www.digital-metaphors.com
Best regards,
Nard Moseley Digital Metaphors www.digital-metaphors.com
I have Subtotal which will accumulate detail amount. Before the Subtotal is printed, I want to add 3 field value from other other dbpipeline.
Setting: Drop Subtotal on ppSummaryBand1, and set DataType to dtCurrency I set CalcComponent to ppDetailBand1, and CalcType to veTraversal
Problem: Subtotal was printed correct before I add 3 field value from dbPipeLine. But printed wrong Subtotal value after adding 3 field value. I put 3 field value calculation on the SummaryBandBeforeGenerate. Any steps step are missing ?
Alternatif way: Now, I create dummy variable called vCalcSubtotal and drop it on vCalcSubtotal on DetailBand Place Subtotal.value := Subtotal.value + detail amount on vCalcSubtotal.OnCalc Add 3 field value on SummaryBandBeforeGenerate Result >>> It print correct Subtotal
Question: Is there any beter way to do this with cleaner coding without Dummy variable like vCalcSubtotal above?
- to create a simple subtotal in the SummaryBand, add a Variable (Variable1) to the SummaryBand and implement the Variable.OnCalc to accumulate the results.
Value := Value + myPipeline['AmountPaid'];
- to add three more fields from another pipeline, add a second Variable (Variable2) to the SummaryBand. Use the CalcOrder dialog to set Variable2 to calculate after Variable1. Implement the OnCalc event handler
Value := Variable1.Value + myPipeline['Field1'] + myPipeline['Field2'] + myPipeline['Field3'];
Note: Always use the Timing.. dialog to configure the timing. For most calculations, use the default veTraversal for the CalculateOn. And do not set the CalcComponent to DetailBand - the dialog will not allow you to do this.
-- Nard Moseley Digital Metaphors www.digital-metaphors.com
Best regards,
Nard Moseley Digital Metaphors www.digital-metaphors.com
Comments
DetailBand before print. See the Developers Guide Tutorials and the
Calculations thread of the Tech Tips newsgroups. Here is a quick overview...
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.
--
Nard Moseley
Digital Metaphors
www.digital-metaphors.com
Best regards,
Nard Moseley
Digital Metaphors
www.digital-metaphors.com
Before the Subtotal is printed, I want to add 3 field value from other other
dbpipeline.
Setting:
Drop Subtotal on ppSummaryBand1, and set DataType to dtCurrency
I set CalcComponent to ppDetailBand1, and CalcType to veTraversal
Problem:
Subtotal was printed correct before I add 3 field value from dbPipeLine.
But printed wrong Subtotal value after adding 3 field value.
I put 3 field value calculation on the SummaryBandBeforeGenerate.
Any steps step are missing ?
Alternatif way:
Now, I create dummy variable called vCalcSubtotal and drop it on
vCalcSubtotal on DetailBand
Place Subtotal.value := Subtotal.value + detail amount on
vCalcSubtotal.OnCalc
Add 3 field value on SummaryBandBeforeGenerate
Result >>> It print correct Subtotal
Question:
Is there any beter way to do this with cleaner coding without Dummy variable
like vCalcSubtotal above?
- to create a simple subtotal in the SummaryBand, add a Variable (Variable1)
to the SummaryBand and implement the Variable.OnCalc to accumulate the
results.
Value := Value + myPipeline['AmountPaid'];
- to add three more fields from another pipeline, add a second Variable
(Variable2) to the SummaryBand. Use the CalcOrder dialog to set Variable2 to
calculate after Variable1. Implement the OnCalc event handler
Value := Variable1.Value + myPipeline['Field1'] + myPipeline['Field2'] +
myPipeline['Field3'];
Note: Always use the Timing.. dialog to configure the timing. For most
calculations, use the default veTraversal for the CalculateOn. And do not
set the CalcComponent to DetailBand - the dialog will not allow you to do
this.
--
Nard Moseley
Digital Metaphors
www.digital-metaphors.com
Best regards,
Nard Moseley
Digital Metaphors
www.digital-metaphors.com