Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2024-01

FPReport: Split text across two or more pages

9 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Unknown author

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. 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 ...

Many thanks in advance!

Regards,
Pique7

Reply by email

Michael Van Canneyt
to Unknown author
Pique7 wrote 8 lines
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 ?

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.

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.

Michael.

Reply by email

Pique7
to Michael Van Canneyt

On Tue, 2 Jan 2024 00:02:35 +0100 (CET)

Michael Van Canneyt wrote 14 lines
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.

Show quoted text 9 lines
> 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?

Show quoted text 6 lines
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.

So in a nutshell, I think I need a function like "Continue (data) band on the next page if remaining space is insufficient". 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.

Show quoted text 5 lines
Michael. _______________________________________________ fpc-pascal maillist - https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply by email

Michael Van Canneyt
to Pique7
Pique7 wrote 25 lines
On Tue, 2 Jan 2024 00:02:35 +0100 (CET) Michael Van Canneyt via fpc-pascal 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.

Show quoted text 13 lines
>> 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)

Show quoted text 24 lines
> 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.

Reply by email

Pique7
to Michael Van Canneyt

On Wed, 3 Jan 2024 13:00:10 +0100 (CET)

Michael Van Canneyt wrote 110 lines
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 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 - https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply by email

Michael Van Canneyt
to Pique7
Pique7 wrote 18 lines
> 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! :-)

I am always open for improvements.
Please do send me your sources or a diff...

Michael.

Reply by email

Pique7
to Michael Van Canneyt

On Mon, 8 Jan 2024 22:08:16 +0100 (CET)

Michael Van Canneyt wrote 25 lines
On Mon, 8 Jan 2024, Pique7 via fpc-pascal wrote: >> 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! :-) I am always open for improvements. Please do send me your sources or a diff...

I have sent an email direct to your email address, or rather, two emails (corrected version).

Show quoted text 5 lines
Michael. _______________________________________________ fpc-pascal maillist - https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply by email

Pique7
to Michael Van Canneyt: I am always open for improvements. Please do send me your sources or a diff... Michael.

On Mon, 8 Jan 2024 22:08:16 +0100 (CET)

Michael Van Canneyt wrote 27 lines
On Mon, 8 Jan 2024, Pique7 via fpc-pascal wrote: >> 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! :-) I am always open for improvements. Please do send me your sources or a diff... Michael.

I have just started to resume my work on FPReport. I have found some errors in my first version and currently I am trying to add RTF support. I utilize TRichMemo for this because I think it is sufficient for my case (I only develop and test for Windows 10/11 at the moment). Also SVG support is wanted. What would be an appropiate way to provide my work and partial results? As I deal with the FPC source code, your opinion and suggestions might be particularly meaningful.

_______________________________________________ fpc-pascal maillist - https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply by email

Michael Van Canneyt
to Pique7
Pique7 wrote 33 lines
On Mon, 8 Jan 2024 22:08:16 +0100 (CET) Michael Van Canneyt via fpc-pascal wrote: > > > On Mon, 8 Jan 2024, Pique7 via fpc-pascal wrote: > >>> 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! :-) > > I am always open for improvements. > Please do send me your sources or a diff... > > Michael. I have just started to resume my work on FPReport. I have found some errors in my first version and currently I am trying to add RTF support. I utilize TRichMemo for this because I think it is sufficient for my case (I only develop and test for Windows 10/11 at the moment). Also SVG support is wanted. What would be an appropiate way to provide my work and partial results? As I deal with the FPC source code, your opinion and suggestions might be particularly meaningful.

SVG support for FPC (and consequently FPReport) is on my wishlist. RTF support using TRichmemo is useless for FPC itself as FPReport needs to be free of LCL or other dependencies. If at some point RTF support is added, it will be using the RTF parser included in Free Pascal.

If you wish to submit contributions, you can supply patches using the gitlab issue tracker. The RTF support for FPReport can of course be submitted to the Lazarus issue tracker or kept on github or some other repository...

Michael.

Reply by email