Two reports into one Preview FR FMX

I would like to use 2 similar frxReports to load their results into the same frxPreview component and then print them using frxPreview.Print.

When I try this, only the contents of the second report is in the Preview even though I pass in False for the ClearLastReport parameter.

Is there a way to put the contents of 2 different reports into one Preview?

Comments

  • gpigpi Volnovakha, Ukraine

    Use

    frxReport1.Preview := nil;

    frxReport1.PrepareReport(True);

    frxReport1.PrepareReport(False);

    frxReport1.Preview := frxPreview1;

    frxReport1.ShowPreparedReport;

  • Thank you. I am studying your suggestion.

    I see no reference to a second frxReport, such as frxReport2. Should the second PrepareReport line be the following?

    frxReport2.PrepareReport(False);

    If so, should there also be the following line?

    rxReport2.Preview := frxPreview1;

    If that is correct, then the sequence would be this?

    frxReport1.Preview := nil;

    frxReport1.PrepareReport(True);

    frxReport2.PrepareReport(False);

    frxReport1.Preview := frxPreview1;

    frxReport2.Preview := frxPreview1;

    frxReport1.ShowPreparedReport;

  • My modified scheme would also need this line at the top:

    frxReport2.Preview := nil;

  • G'day Mike,

    I haven't tested your solution, but would caution you to check this for memory leaks. Those "Preview := nil" statements worry me 😳

    Cheers, Paul

  • edited December 2020

    Thanks. I have seen some info in the docs that says there are situations in which FR is somehow handling the memory, and I've run the code I listed and got no leaks.

    Unfortunately, using the code still doesn't avoid the problem of only the contents of the 2nd report being present in the Preview.

    I will play around with some sequence variations to see if it makes a difference. I'm not sure if the original poster took into account that I'm loading the preview from 2 different report components into the Preview. The code calls for frxReport1.ShowPreparedReport when I'd think I'd need that for frxReport2, but doing that seems to erase the contents of frxReport1 in the Preview.

  • On page 12 of FR4.6.ProgrammerManual-en.pdf

    I see that my attempt may be explicitly precluded by changes made in FR3. Here is some text from that page:

    "In the FastReport 3 version, one TfrxReport component can display only one report in the preview window (unlike the FastReport 2.x version). That is why one should run a report either in a separate TfrxReport object, or in the same one, but the current report must be erased."

    If I understand this correctly, and it hasn't been changed to re-enable my desired approach in some later FR version, I will simply have to use a different Preview component for each separate Report component, if I want their contents to be simultaneously visible.

  • G'day Mike,

    Interesting. GPI ddin't point that out, so maybe it can be done. anyway...

    When I am back in front of my development machine I'll remind myself what we do for previewing "composite reports" which our main App has many...

    Cheers, Paul

  • edited December 2020

    Thank you Paul. Yes, as long as the composite reports are not limited to various runs of one Report component, and this process specifically allows the output to be seen in just one Preview component, it might work for me. I can't find anything that specifically addresses appending to the current contents of a Preview.

    I am also hoping to avoid explicitly creating any kind of intermediate files, partly because this app is in FMX and might also run on Android and maybe even iOS, and it would be nice to not have to deal with those variations, which will vary even more over a span of time in which those platforms change their practices or rules.

    If this cannot be accomplished, I'm pretty sure it's not a critical problem and some people in the eventual end-user community might prefer to see the contents of the 2 different Reports as separate reports. I'm just trying to avoid locking them into that, if it's practical.

    On page 10 (Chapter 1.9) of the same doc, there is information about loading contents from 2 different report output files, using just one Report component for both. If this could work to load them into one Preview component, even when those 2 output files were created with 2 different Report components that are not identical, then this seems like it could work for me. It has the disadvantage of requiring the creation of those output files first, but it would be one way of achieving the contents of 2 different reports in one Preview. But the code example doesn't suggest that the general create-then-load technique could use saved report contents that varies as I need. It's ambiguous on this question.

  • OK, this might not be helpful at all!

    A couple of "caveats" first:

    • We do most of our work with Vcl still (so no FMX examples to cite)
    • All of our reports are instantiated in individual Units with both the Delphi and FR3 based on common templates
    • We have "automated" a lot of the smarts in a Unit that provides "common" functions for all reports / composites

    The simplest of these "composites" has six reports (see screenshot below) and the most complex one over 20 (for End of Financial Year Reporting).

    If this doesn't sound too far from what you are trying to achieve, let me know and I'll put a bit of effort into "distilling" the code down to its simplest elements...


    Cheers, Paul

    FYI - Screenshot is of the "thumbnails" for the Report. Each of the Charts is a separate Report as are the two text reports (different alternating band colours). Two other Reports have been scrolled past in this capture. Oh and the blank pages are because I opted for double-sided printing when I invoked the "Composite Report". 😉


  • That does seem like an approach that would work if it also works in FMX.

    If it's not too much work to distill it down to just 2 Report components and their output is appended in one Preview component, that would be nice. But I'm not asking you to spend much time on it unless you think your work can be further leveraged.

    And if it's something worth doing for you, I can quickly test it in an FMX app and let you know if it works for me too.

  • gpigpi Volnovakha, Ukraine

    Should the second PrepareReport line be the following?


    No. Use frxReport1.PreviewPages.AddFrom(frxReport2);

  • edited December 2020

    Ah, that sounds like it will work.

    I do not see AddFrom in the ProgrammerManual document I am looking at.

    Is there a different version of the document that has a reference to it?

  • gpigpi Volnovakha, Ukraine

    Is there a different version of the document that has a reference to it?

    No


  • What is the proper way to un-assign a preview component to a report component? (so that I can choose the one and only Report component that will be tied to the Preview component)

    I think I need this because I am now using

    frxReport1.PreviewPages.AddFrom(frxReport2);

    to get the contents from a subsequent report into the Preview that is assigned to the prior frxReport1.

    If frxReport1 were ALWAYS non-blank, then it could always be the report component tied to the preview component. But sometimes that report would have no contents so I intend to tie frxReport2 to the Preview directly in that case. Then a frxReport2.PreviewPages.AddFrom(frxReport3); could add additional pages if the 3rd report is non-blank.

  • My current process correctly gathers the pages from multiple reports and assembles them into the Preview component that is assigned to one of the reports. (the first of multiple reports). This is accomplished using the following lines

    frxReport1.Preview := frxPreview1;

    frxReport1.PreviewPages.AddFrom(frxReport2);

    frxReport1.PreviewPages.AddFrom(frxReport3);

    That works great when Report1 is non-blank because its contents appears in the Preview due to the first line, above.

    My problem arises when the reporting process is performed again when it results in frxReport1 with no matching records so no output. To me, it would make sense to execute the following code in that scenario:

    frxReport1.Preview := nil;

    frxReport2.Preview := frxPreview1;

    frxReport2.PreviewPages.AddFrom(frxReport3);

    However, I have been advised by Paul, above, that setting a Preview to nil (as shown in the code suggested by gpi, further above) is not valid and indeed results in crashes I cannot tie to anything else.

    Hence my question about how to un-set or un-assign the value of frxPreview1 so that the value of frxReport1.Preview reverts to what it was before it was set to be frxPreview1.

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.