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

Conditional printing based on a variable

edited July 2003 in General
Hi;

i use a string variable that helps me to decide when to print some fields
on my detail band. My report PassSetting is set to 'psTwoPass', because i
use a ppSystemVariable to print a PageSetDesc.

Because the "two passes" my variable doesnt work good. Controlling the
variable's change only on the SecondPass solves the problem if i dont use
the Preview and print my report from the preview form.

Here is the code (ximpguia is the variable):

if Papeleta.SecondPass = true then
if ximpguia <> (Jabil.DFACGUIAM.value+Jabil.DFACGUIAH.value) then
begin
plguiam.Visible := True;
plguiah.Visible := True;
ximpguia := (Jabil.DFACGUIAM.value+Jabil.DFACGUIAH.value);

plbultos.Caption := FloattoStr(Jabil.GUIASBULTOS.value);
plpeso.Caption := FormatFloat(',0.000',Jabil.GUIASKILOS.value);

plbultos.Visible := True;
plpeso.Visible := True;
end
else
begin
plguiam.Visible := False;
plguiah.Visible := False;
plbultos.Visible := False;
plpeso.Visible := False;
end;


Any sugestions?

Thanks in Advance.

Comments

  • edited July 2003
    Arturo,

    Be sure to use the TppVariable.OnCalc event to make any calculations or
    changes to a variable. See the article below for more information.


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

    --
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
This discussion has been closed.