Recent

Author Topic: [Solved] How to conditionally print fields or lines in a report  (Read 1484 times)

JanRoza

  • Hero Member
  • *****
  • Posts: 626
    • http://www.silentwings.nl
I'm at a loss with lazReport.
What I want to achieve is to print or not to print certain fields and lines in a report depending on the content of some other field.
All those fields and lines are in the Headerband.
I tried to solve this by using scripting on a field in the report, but all I have achieved so far is a dump in one case or no visible effect at all.
Unfortunately the documentation with lazReport is not a big help for me in this case.

First scripting attempt (hiding by printing white on white:
Code: Pascal  [Select][+][-]
  1. if Memo2.Text = ''
  2. then begin
  3.          line1.FontColor := clWhite;
  4.          memo3.FontColor := clWhite;
  5. end
  6. else begin
  7.          line1.FontColor := clBlack;
  8.          memo3.FontColor := clBlack;
  9. end;
  10.  

Second attempt (trying to hide the fields and lines):
Code: Pascal  [Select][+][-]
  1. if Memo2.Text = ''
  2. then begin
  3.          line1.Visible := false;
  4.          memo3.Visible := false;
  5. end
  6. else begin
  7.          line1.Visible := true;
  8.          memo3.Visible := true;
  9. end;
  10.  

What am I missing or am I on the wrong track all together?
Can anyone give me some hints for a working solution?

« Last Edit: August 13, 2021, 01:17:25 am by JanRoza »
OS: Windows 10 (64 bit) / Linux Mint (64 bit)
Laz: Lazarus 2.0.12 FPC 3.2.0
       CodeTyphon 7.6 FPC 3.3.1

GAN

  • Sr. Member
  • ****
  • Posts: 338
Re: How to conditionally print fields or lines in a report
« Reply #1 on: August 13, 2021, 12:20:12 am »
This script I uses in PageHeader in a field:

Code: Pascal  [Select][+][-]
  1. if somecondition then visible:=false;

Take a look to the documentation of FastReport, es very similar: https://www.fast-report.com/public_download/UserManual-en.pdf
« Last Edit: August 13, 2021, 12:23:17 am by GAN »
Lazarus 2.0.8 FPC 3.0.4 Linux Mint Mate 19.3
Zeos 7̶.̶2̶.̶6̶ 7.1.3a-stable - Sqlite 3.32.3 - LazReport

https://searchlazarus.blogspot.com/

JanRoza

  • Hero Member
  • *****
  • Posts: 626
    • http://www.silentwings.nl
Re: How to conditionally print fields or lines in a report
« Reply #2 on: August 13, 2021, 01:17:04 am »
After strolling around this forum I found an old item on a different subject where GetMem supplied a report example using the OnEnterRect event of the report which was very useful.
I adapted that example to my needs and it works perfect for me.
It's a completely different solution and I never would have known to use that report event as its name is not very obvious but it does suite my needs.

My solution in the OnEnterRect event:
Code: Pascal  [Select][+][-]
  1.        if (View as TfrMemoView).Name = 'Memo152'
  2.        then if DataModule1.qryRapportWeging.FieldByName('G1a').AsString = ''
  3.             then (View as TfrMemoView).Memo.Text := ''
  4.             else (View as TfrMemoView).Memo.Text := DataModule1.qryRapportWeging.FieldByName('G2a').AsString + ' x ' +
  5.                                                                            DataModule1.qryRapportWeging.FieldByName('Ba').AsString;
  6.  

OS: Windows 10 (64 bit) / Linux Mint (64 bit)
Laz: Lazarus 2.0.12 FPC 3.2.0
       CodeTyphon 7.6 FPC 3.3.1

 

TinyPortal © 2005-2018