[fpc-pascal] FPReport: Split text across two or more pages
Pique7
pique7 at gmx.net
Mon Jan 8 18:58:40 CET 2024
On Wed, 3 Jan 2024 13:00:10 +0100 (CET)
Michael Van Canneyt via fpc-pascal <fpc-pascal at lists.freepascal.org> wrote:
>
>
> On Tue, 2 Jan 2024, Pique7 via fpc-pascal wrote:
>
> > On Tue, 2 Jan 2024 00:02:35 +0100 (CET)
> > Michael Van Canneyt via fpc-pascal <fpc-pascal at lists.freepascal.org> wrote:
> >
> >>
> >>
> >> On Mon, 1 Jan 2024, Pique7 via fpc-pascal wrote:
> >>
> >>> Hello everyone,
> >>>
> >>> I have already asked this and related questions in the Lazarus Forum.
> >>>
> >>> I want to improve FPReport in order to use it for my project - if possible.
> >>> Some features are missing for this, e.g. automatic splitting of text across two or more pages.
> >>>
> >>> As far as I can judge, the current development status of FPReport does not really allow me to extend it without modifying the original classes.
> >>
> >> Why do you think so ?
> >
> > Thanks for your reply. I am not sure whether I have defined the problem
> > correctly from my point of view. I have tried both FPReport and
> > LazReport. LazReport is able to create page breaks within a band
> > automatically (though not always correctly calculated). This is traceable
> > by viewing the source code of LazReport. I haven't found anything similar
> > in the source code of FPReport and thus considered to implement it myself.
> > But I haven't found a straightforward solution.
>
> There is no straightforward solution if you wish to break a memo.
>
> The layouter is not equipped for splitting bands.
>
> >>> What approach do you suggest? Would this be feasible/reasonable at all? I ask this because I am new to Lazarus and FPC. I come from Delphi 2007 ...
> >>
> >> If you ask me, it's perfectly doable without any changes.
> >>
> >> There is a demo that shows how to print a text by splitting it in lines, and
> >> simply printing a band per line. That will have the same effect as what you
> >> seem to need. Basically, it means using a TStringList as a data source
> >> for a (sub)band instead of using it as the text of a single memo.
> >
> > Unfortunately I couldn't find the demo program you mention. I know the
> > fcl demos in "source\packages\fcl-report\demos". Admittedly I haven't
> > examined every single unit yet. Most of the demo reports get the data
> > from a TStringList. Is it this what is meant?
>
> Yes. Normally you'll be using a dataset-based "data loop" (TFPReportData).
>
> But the data loop can be an event-based loop, which uses a TStringList to
> define the items in the loop. (an instance of TFPReportUserData is used for this)
>
> >> What you may need to do is to split the text "correctly" over the lines of the
> >> TStringList, but that should be easily doable. All you need is a function to
> >> calculate the length of the text.
> >>
> >> I think this is perfectly doable without any changes to the original code.
> >
> > Okay, probably you're right and I think I understand the basic idea but I
> > still don't know how to transfer it to my case. I have a table with
> > several columns containing multiline text. The data comes from a TDataSet
> > descendent. If one the cells (Memo) content is to large to fit on the
> > current page, the whole band should be split at the correct position and
> > continued on the next page, e.g.:
> >
> > [PAGE 1 - DATABAND 1 (bottom of page)]
> > COL 1-1 COL 2-1
> > COL 1-2 COL 2-2
> > COL 1-3 COL 2-3
> >
> > [PAGE 2 - DATABAND 1 (continued)]
> > COL 1-4 COL 2-4
> > COL 1-5
> >
> > I also have one report with one column containing richtext (RTF). I doubt
> > that the TStringList solution will be helpful in this case.
>
> If RTF is a requirement, in that case you can desist your efforts:
> RTF is not supported in FPReport. A limited subset of html is.
>
> I don't know if RTF is supported in lazreport. Maybe on windows it is.
>
> FPC comes with an RTF parser, but it would require a large amount of work to
> integrate that in FPReport. RTF is a huge subject.
> It would be a nice addition, no doubt.
>
> >
> > So in a nutshell, I think I need a function like "Continue (data) band on
> > the next page if remaining space is insufficient".
>
> At the moment, I don't see how to create this function.
> IMO It would require a major rewrite of the layouter to introduce this.
>
> > If you still think
> > your suggested approach is suitable, please let me know. Maybe it is
> > obvious, but at the moment it seems that I don't make any progress.
>
> Disregarding the RTF for a moment, you'd need to save the contents of the
> text fields in a TStringlist instance in the 'afterscroll' event of the dataset.
>
> This instance can then be used to create a data loop for a sub band
> (using TFPReportUserData).
> The band connected to the dataset (the master band) would not print anything.
> Instead, the child band will print the cell content line by line and split it over pages.
>
> From your drawing, it is not quite clear how you construct your columns,
> if you're using columns, I'm not sure how the band will behave.
>
> Michael.
Thanks again for your suggestions. I haven't tried it yet but now I've got the idea. Your are so optimistic but I still fear all the things which might make troubles in a more complex report with grouping, master/detail data, calculations, layout adjustments, HTML tags, table borders etc.
However, finally I've tried to extend/improve the original FPReport classes and now I really have a FPReport version that supports band splitting for simple FPReportMemos.
I was not able to implement this using inheritance - I've had to change the original source code in the FPC folder.
Without any doubt there are still many bugs in my FPReport. But if you want a copy, let me know! :-)
> _______________________________________________
> fpc-pascal maillist - fpc-pascal at lists.freepascal.org
> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
More information about the fpc-pascal
mailing list