frxDBDataset OnNext event fires more than once per record in FR FMX2

Using the latest FR FMX2 with Delphi 10.3.3, I am using code in DETAIL DBDataset's OnNext to create a TChart and export it to a BMP file (with a serialized name), and then I use LoadFromFile to get the image into the report. That works great even though the frxPictureView is on the SUB-Detail band.

All of the data prints correctly for Master/Detail/SubDetail, so we know all of the MasterSource values must be correct.

But I'm having a problem because the OnNext code is generating multiple BMP files for each record, and I log the activity when OnNext code runs so I see that it is fired more than once per record. For some reason, this does NOT present a problem the first time I run the report (generating a Preview), so this makes me think it would be better if OnNext fired only once per Detail record.

Before I try to create a work-around by using some global count to EXIT the OnNext code for subsequent runs for the same Detail record, I think it would be good to get some guidance on the following:

0) Can you point me to the documentation of the DBDataset events, that describes their typical applications?

1) If OnNext doesn't normally get fired multiple times per record, then this would suggest something I'm doing incorrectly is triggering that, despite the fact that the data in the report is all correct.

2) If it is normal for OnNext to get fired multiple times per record, should I be using a different event?

3) Would it work better to put the frxPictureView on the Detail band because it is the OnNext of the DBDataset that corresponds to that band where I have my code?

4) Though it is each Detail record that must trigger the handling of the BMP, should I be using the OnNext of the Master instead of Detail?

5) Or should I be using a completely different approach to generating and loading BMP files for each Detail record?

Comments

  • I have implemented a work-around in the OnNext event for the Detail table. I simply keep track of whether the current record's id value is the same as the last time OnNext was fired, and if so, just exit;

    Since OnNext is apparently not fired for the first record, I also call OnNext from OnFirst. This combination appears to yield the same behavior as a Delphi DataSet's OnScroll, thus accommodating the way I'm used to working. However, I have no idea if this is the most sensible approach.

    All is working fine, now. My only concern is that my inelegant approach is not a useful template for unanticipated scenarios I might encounter, so I'd still like to hear if my approach sounds like a bad idea.

  • 0) Can you point me to the documentation of the DBDataset events, that describes their typical applications?

    TfrxDBDataset events doesn't used typically

    2) If it is normal for OnNext to get fired multiple times per record, should I be using a different event?

    It is normal for last record of the group

    3) Would it work better to put the frxPictureView on the Detail band because it is the OnNext of the DBDataset that corresponds to that band where I have my code?

    Try to use TfrxReport.OnBeforePrint event and detect when this event called for TfrxPictureView

  • Thank you for that information. My work-around currently provides the needed result, so I might continue to use it, but right now I am again trying to use Report.OnBeforePrint in order to use your advice. I do not remember why I abandoned that approach and now I may rediscover the reason.

    The first thing I did to test using Report.OnBeforePrint now, was to log the count of each time this event is fired when I run the report using my work-around. I see that it is fired 657 times for the report that has 1 record. It would not be a good idea to needlessly re-create a TChartand export it to a BMP file from a TChart and load that BMP file into a frxPictureView 656 times after it is created and loaded the first time, so I would need to apply logic that is similar to my work-around for using Dataset.OnNext, to avoid all that extra work.

    6) Do you suggest that we should never use Dataset events like OnNext for any purpose?

    7) Is it normal for Report.OnBeforePrint to be called so many times?

    8) Do you agree that I would need to use a work-around to avoid the unnecessary processing in Report.OnBeforePrint?

    9) What do you think of using frxPictureView.OnBeforePrint to do the same work? (This appears to require the addition of a lot of complexity to make the Delphi objects and variables visible to this event in the report.)

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.