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

How to use variables in RB

edited June 2002 in General
I am considering the possibility of migrate from QuickReport to
ReporBuilder. I had downloaded the trial version. But I could no find a
way of to use in the report, data that is produced by calculations made by
the system. Trying to explain better: The UnitA made several calculations
and get values V1, V2 .... Vn and I would need to have this V1 ... Vn
printed in the Report. How to do that ?
Thanks
Edison

Comments

  • edited June 2002
    Make the migration...you won't regret it

    I use two methods of achieving this;
    a) Either the variable is the result of an SQL query in which case I attach
    this to a data source and link this to a DbText component
    b) Otherwise I put a label on the report and use the reports BeforePrint
    method to 'squirt' the result to the label

    Regards

    Glenn
    Key-Data Systems
  • edited June 2002
    Dear Glenn
    Thank you. I tryed the sugestion B, and it works, since I use the
    BeforePrint in the report component ( clicking over the component in the
    form where it is placed ). I had tryed before to use a label in the report
    and the beforeprint in the "Calc" palete of the report design tool ( with
    no sucess ). What I am undestanding is that the report didn't "see"
    anything even from the form where it is placed. Am I correct ? So, if I
    build (by calculations ) a collection of values ( that could not be accessed
    directly by a SQL query ) I could not use then in the report. If my
    assertion is correct, how to use this type of data ? Is it possible to have
    the calculations done in the report itself ?
    ( could you understand my question with my bad english ? ). Thank you
    Edison

  • edited June 2002
    The following article describes the use of the TppVariable component for
    calculations:

    ------------------------------------------------------------------------
    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.



    --
    Tech Support mailto:support@digital-metaphors.com
    Digital Metaphors http://www.digital-metaphors.com




    --
    Cheers,

    Jim Bennett
    Digital Metaphors

  • edited June 2002
    Thank you very much. I will try both options and now I have sufficient
    information to do it.
    Edison


This discussion has been closed.