Forum > LazReport

[Solved] How to conditionally print fields or lines in a report

(1/1)

JanRoza:
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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---if Memo2.Text = ''then begin         line1.FontColor := clWhite;         memo3.FontColor := clWhite;endelse begin         line1.FontColor := clBlack;         memo3.FontColor := clBlack;end; 
Second attempt (trying to hide the fields and lines):

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---if Memo2.Text = ''then begin         line1.Visible := false;         memo3.Visible := false;endelse begin         line1.Visible := true;         memo3.Visible := true;end; 
What am I missing or am I on the wrong track all together?
Can anyone give me some hints for a working solution?

GAN:
This script I uses in PageHeader in a field:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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

JanRoza:
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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---       if (View as TfrMemoView).Name = 'Memo152'       then if DataModule1.qryRapportWeging.FieldByName('G1a').AsString = ''            then (View as TfrMemoView).Memo.Text := ''            else (View as TfrMemoView).Memo.Text := DataModule1.qryRapportWeging.FieldByName('G2a').AsString + ' x ' +                                                                           DataModule1.qryRapportWeging.FieldByName('Ba').AsString; 

Navigation

[0] Message Index

Go to full version