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

data duplicated when export to a file

edited October 2004 in General
Hi,

I'm using Rbuilder 5.1 with Delphi7 pro.

The problem is that duplicated data is occured when I put the export
function in AafterPrint. I've tried this with AfterGenerate too. The result
is not different. I only want to output the line once it has actually
finialised where its going to print on the report. In fact, output of the
report is fine. Only the export module has problems when the pages are more
than 1 page.

My report design is below
...
data ( I want to export this data)
^detail band
group1 total
^group1 footer
group0 total
^group0 footer

In my research, this case is happened when starting of new group1 and group0
total(not group1 total) are printed at the same page.

For example,
Report result
-----------------------------------------------------------------------------------------
NEW PAGE START....
Aa1
Aa2
Aa3
subtotal of group Aa
Ab1
Ab2
subtotal of group Ab
subtotal of of group A

END OF THIS PAGE
-----------------------------------------------------------------------------------------

Export file result
-----------------------------------------------------------------------------------------
Aa1
Aa2
Aa1
Aa2
Aa3
Ab1
Ab2
-----------------------------------------------------------------------------------------

My code is

procedure TdmReportTest.ppSummaryBand1AfterPrint(Sender: TObject);
begin
inherited;
exportfunction (It will export only one line)
end;


I'm afraid that you cannot understand what I mean.. It's hard to explain.
Please look for this carefully.
Thanks in advance.

Comments

  • edited October 2004
    Hi Eungi,

    Try placing a stop inside the AfterPrint event and be sure this event is not
    firing more than once. I am a bit unclear about what you are trying to
    accomplish by trying to export your report in the AfterPrint event. Why not
    simply print the report initially directly to an export device after you
    have designed/viewed it?

    --
    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited October 2004
    I'll jump in here since I do some work with Eungi. Basically we want the
    data for the report put into a CSV file. We used to use QuickReports 1.1
    with Delphi 3 for years and we already had code that gave us what we wanted.
    Basically write out a column headings line at the start of print and write
    out a line in the AfterPrint event. This gave us a nice simple CSV file with
    the results we wanted. Move forward a few years and we upgrade our system to
    D7. We had a look around at the different report writers and decided to use
    the one that everybody recommended as being the best out there -
    ReportBuilder. So we upgrade our existing QuickReports reports. Since there
    is no easy way to do this we go ahead with the tedious conversion of them.
    We had an initial look at the export filters and it didn't really give us
    the control we wanted. Also since we had so many reports to do we decided to
    keep the CSV code similar to what we already had in our QuickReports
    reports, code that we were quite happy with. ReportBuilder has a BeforePrint
    event for the report and an AfterPrint event for the detail line. Cool! Read
    the help file a bit more. AfterGenerate seem to be the better choice. The
    help file specifically explains:

    'AfterGenerate differs from AfterPrint in that AfterPrint prints fires evey
    time a band has the opportunity to print. Sometimes the band has the
    opportunity to print, but for various reasons does not (usually printing on
    the next page instead.)'.

    Sounds to me like its saying the AfterGenerate will fire only once and
    AfterPrint will fire multiple times. So we put our export code in the
    AfterGenerate event. Do some simple tests and all looks ok.However, more
    detailed testing shows the AfterGenerate event *is* being fired more than
    once. So we experiment and we find that we get better results using
    AfterPrint instead of AfterGenerate. Move all the code over. Now the client
    has come back saying there is still a problem. The problem Eungi described
    is coming from the fact that it starts to print the details for a group so
    the AfterPrint event fires. But the report has been told to keep the group
    together and it realises the group won't fit on the page, so it moves it to
    a new page and the AfterPrint events fires for the same details again. Which
    is really just doing what the help file said AfterPrint would do.

    So the question becomes is there any way to do something once - when the
    line is actually printed or generated or whatever. It can't be that hard.
    How do the export filters do it?

    Hopefully you have a better understanding of what we are trying to do.

    Jeff


  • edited October 2004
    > So the question becomes is there any way to do something once - when the

    I just checked through ppDevices and ppFilDev and that's way too complicated
    for the simple task we are trying to achieve.

    Jeff
  • edited October 2004
    Hi Jeff,

    A file device (export filter) does not interact with the report engine at
    all as it produces the report. The file device receives a report one page
    at a time, each page consisting of the page settings and an array of
    TppDrawCommands. A TppDrawCommand is an object that holds all the
    information needed to draw a report component to a device canvas (i.e.
    position, size, font, color, etc). The export device loops through these
    DrawCommands and uses the information inside each of them to draw the
    correct output to the specified file. If you are exporting to a CSV file,
    you will need to create something like this. See the ppFilDev.pas file for
    some examples of the built-in file devices included with ReportBuilder.

    --
    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited October 2004
    Thanks for the info Nico but that won't work for us. We need to have access
    to the datasource as the report is being generated not the drawcommands.
    That's why the existing export filters didn't do the job in the first place.

    I find it just unbelievable that there is not an event that gets fired when
    the line is finalised. I quite enjoy using ReportBuilder but there are some
    things where I just find it cumbersome when compared to a 6 year old version
    of QuickReports was much better at. This event for one. Being able to force
    a new page with a simple NewPage method rather as some convulted trick with
    grouping on a variable, as another.

    Man this is going to cost me a lot of time. What I am not particularly happy
    about is that in the help file the Band.AfterGenerate reads as if it should
    only fire once and Band.AfterPrint will fire multiple times. If it had of
    said that AfterGenerate could also be fired multiple times then we would not
    have converted the existing QuickReports the way that we did. As we were
    converting them we would have used whatever 'new' method we were able to
    come up with.

    Jeff


  • edited November 2004
    Hi Jeff,

    Although the Band.AfterGenerate may fire more than once per traversal, it is
    possible to add a conditional statement to this event to prevent certain
    code from executing when the event is fired for the second time. You could
    perhaps cache one of the detail field values, and check this value before
    the aftergenerate code fires. If the field value is the same as the cached
    value, you could skip the code you do not want executed twice.

    --
    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited November 2004
    Thanks Nico. I had thought of this but it was easy for us to copy the
    existing code to the report's AfterPrint and do our own loop through the
    dataset.

    It's just that this sounds like such a simple thing to provide, its
    unbelievable to me that its not there. But then I don't know the underlying
    RB code either :-)

    Cheers

    Jeff

This discussion has been closed.