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

Problems with displaying (showing/hiding) a variable

edited March 2003 in General
Hi,

i'm new to ReportBuilder (i use the Delphi 5's version) and i have problems
when formatting output (precisely, the position of a variable). I read data
from a query (through a DBPipeline) and each row which is displayed in the
detail band has a numeric field which has to be summed up within a group -
the group is defined by another field (i.e. when the "group" field changes,
the TppVariable which holds the sum has to be set to 0 - and then has to
hold the sum for the next group). The problem is that i want the sum field
displayed only next to the last record of the group and not every time the
detail band prints.

I tried to solve this problem by putting a "dummy" variable in the detail
band and set it's Calculate On property (selecting Timing... from the popup
menu) to GroupEnd (and choosing the group i have on the report). I use the
dummy's onCalc event only to set the visible property of the summary
variable to true when the group end is reached. The problem is that when i
set the visible property to true (in the dummy's onCalc), it's too late,
since it does not have any effect on the variable. I suppose that when the
last record of the group is fetched, the dummy's onCalc doesn't execute - it
executes only when the record after this is fetched. The result is that when
it executes, the variable with the sum is already printed, but not visible,
since it's visible is set to false - it becomes visible only when the next
record (in the next group) is printed.

Maybe it's better if i show an example:

group col. | field1 | summary field
-----------------------------------
1 | 1000 |
1 | 1500 |
1 | 500 | 3000
2 | 100 |
2 | 300 | 400
3 | 1000 | 1000


As you can see the sum of field1 in the first group is 3000 and it's
displayed only at the end of the group (similarly for other groups). In my
case (when i set the visible to true), it wouldn't be displayed there since
the dummy's onCalc executes only after the summary field has been printed
(and as said with the visible property set to false).

How can i solve this problem? I think i should somehow know in advance when
i'm on the last record in the group and then immediately set the
summary_filed.visible to true, but i don't know how to do that.

Any suggestions would be very very appreciated

Thanx

Comments

  • edited March 2003
    Use the band's BeforePrint event to set the visibility of a control in a
    band. This is the best event for this.

    Use the Variable's OnCalc event to calculate a value for the variable. This
    is the onyl event ot use reliably for any calculations, because other events
    fire more than once in some cases as the report needs to do this in order to
    correctly paginate.

    If you need to know the "LookAhead" total to determine the visibility, then
    one approach is to use a two pass report. Set Report.PassSetting to
    psTwoPass. The first pass determines the pagination and fires the events,
    but no pages are output. This way you can build a TList to store the primary
    key values for the records that you want to hide when the variable goes to
    print in the second pass to an actual device. There are Report.FirstPass and
    SecondPass boolean read only properties you can use in your event handlers
    to optimize your code to not execute but for only one pass.

    Cheers,

    Jim Bennett
    Digital Metaphors


  • edited March 2003
    thanx, i solved the problem

  • edited March 2003
    > thanx, i solved the problem

    Why not share your solution - as you were willing to take our words?

    Cheers
    Bernd
    order
    events,
    to
    handlers
  • edited March 2003
    ok

    as Jim Bennett suggested, i used a two pass report. I also added a variable
    in the detail section, which has the function of counting the current line
    number (Jim suggested to make a list of primary keys, but in my case the key
    has 6 fields...) In the first pass i filled a List with the line numbers
    that will be printed in the second pass; so in the BeforeGenerate event of
    the detail band (the BeforePrint sometimes skipped a line???) i put a code
    which checks if the current line number is in the list - if it is, it's
    printd, otherwise it's not.

    Cheers


  • edited March 2003
    Yes, the Detailband.BeforePrint event fires at the bottom of the page to see
    if there is space so that the detail band can begin printing. If it doesn't
    fit, then it moves to the next page and refires the BeforePrint event when
    it tries to see if it can fit on the top of the next page. If it can
    successfully begin printning the band, then the BeforeGenerate fires.


    Cheers,

    Jim Bennett
    Digital Metaphors


This discussion has been closed.