Accessing the current record when printing the detail band
Hello,
I would like to access the current record of a data set, when printing the
detail band. (The reason for this is that I use InstantObjects and I want to
do something with the objects = records. However, I am not sure, if
InstantObjects might have any influence on solving my problem).
How can I access the fields of the current record, when printing the detail
band. At the moment, I am using the OnBeforePrint event of the detail band
to do some calculatons. But in fact, I can't really get any values of the
record. However, it is possible to print some properties using standard
ReportBuilder components.
Thanks for any help!
Mike :-)
I would like to access the current record of a data set, when printing the
detail band. (The reason for this is that I use InstantObjects and I want to
do something with the objects = records. However, I am not sure, if
InstantObjects might have any influence on solving my problem).
How can I access the fields of the current record, when printing the detail
band. At the moment, I am using the OnBeforePrint event of the detail band
to do some calculatons. But in fact, I can't really get any values of the
record. However, it is possible to print some properties using standard
ReportBuilder components.
Thanks for any help!
Mike :-)
This discussion has been closed.
Comments
1. You can access the current record by using the Report.DataPipeline
property. For instance manually calculating a sum would look something like
the following:
Value := Value + Report.DataPipeline['AmountPaid']; //AmountPaid being the
field name.
2. When making calculations, you probably do not want to use the
DetailBand.BeforePrint event. This event has the possibility of firing more
than once per traversal perhaps giving you bad calculation values. By
placing a TppVariable in your detail band you can use its OnCalc event to
make any calculations. The TppVariable.OnCalc event is the only event in
ReportBuilder that is guarenteed to fire only once per traversal. If the
calculations you are making are internal, you can set the
TppVariable.Visible property to False so you will not see it at run time.
See the article below for more information on making calculations in
ReportBuilder.
----------------------------------------------------------------------
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.
--
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
thanks very much for your hyperfast reply. Your answer helped me, although
it took me some time, since I think I mixed up two different problems:
1) At design time, I don't know how many labels I will have in a detail
band, it might be either 4 or 12. However, I decided to created them in the
OnBeforePrint event of the detail band. Rubbish! (Well, now I have a quick
and dirty solution: I put 12 labels into the report, and ini them, when the
frame with the report is initialized, meaning I set those to invisible that
I don't need. Additionally, I ini an array with the 12 labels, so that I can
directly assign them a value later in the OnCalculate event of the
TppVariable. This is not really clean programming, and I'd rather would like
to create the labels at run time, but I think I need some more time to test
this...)
2) I had also implemented the calculation in the OnBeforePrint event of the
band - thanks to your anwer I know now that this was rubbish, too. Now, I am
using the TppVariable, set it to invisible, and use the OnCalculate event
for doing my calculation and the assignment of the values to the 4 or 12
labels.
OK, I don't know, if I was able to explain my problems clearly - however,
your answer had helped me quite a lot finding a feasible solution. Thanks,
and have a nice day!
Mike :-)