LookAhead-Based Calcs

If you are using a LookAhead value from a DBCalc in a variable’s calculation, then be aware that you will get inconsistent results.

The reason for this behavior is that when the DBCalc prints, and if the rest of the detail bands on the page have not generated, then the datapipeline may not been traversed for all of the values that need to be included in the DBCalc’s value. The current report engine handles calculating LookAhead values by letting the DBCalc’s OnCalc fire on the record traversal, as the detail bands generate on the page. Once the page has completed, the DBCalc’s draw command on the page is updated with the latest LookAhead value.

One solution would be to create a calculated fields on your dataset.

Another solution is to not use DBCalcs at all, and instead build the totals in the first pass and use them in calculations during the second pass. Set the Report.PasSetting to psTwoPass. Then as the report generates in the first apss, store the group totals in a TList. Now, the Report.FirstPass and SecondPass (runtime boolean properties) can be used to determine if the report is in the second pass (which will happen when you preview or print). Now you can extract the total for the group from the TList and us it in the variable’s OnCalc event calculation.  Use a variable in the group header band if you want to display the group total there.