Sign in Join

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

Mailing lists / lazarus / 2020-05

Lazreport variables

9 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

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

Santiago A.

Hi:

I want to write a report where even lines are written with no background and odd lines with a light gray background.
The idea is an memo (MemoBackground) in the background of the masterData Band that is gray and I set visible or invisible, according with the line.

I have created a report variable "LineCounter"

In the ColumnHeader band (the report has two columns) I have a Script

Begin
  LineCounter:=0;
end;

In the GorupHeader header I have this script

Begin
  LineCounter:=0;
end;

In the masterData band Script:

begin
  LineCounter:=LineCounter+1;
  MemoBackground.visible:=(LineCounter mod 2 = 0);
end

When I prepare the report, I get "Invalid Variant Type Cast"

After debugging a little, I have found LineCounter is undefined when it is on the right side of assignment.
When It executes  LineCounter:=0; it assigns to a frVariables, a global public var in Unit LR_Class.
But when it tries to get its value it searches en a field "values" of TfrReport.

I've also tried

LineCounter:=[LineCounter]+1;

With brackets, the same result. (Not sure what brackets are for in scripts)

Any hint? What am I missing?

Saludos Santiago A. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20200503/c5382c7d/attachment.html>

Reply by email

Bart
to Santiago A.
PM Santiago A. wrote
I want to write a report where even lines are written with no background and odd lines with a light gray background.

A little bit out of the box thinking :-)

You could add the lines to a TStringGrid (ColCount := 1) and set the
color for the alternating row in OI.
Bart

Reply by email

Santiago A.
to Bart
Bart wrote 9 lines
On Sun, May 3, 2020 at 6:03 PM Santiago A. via lazarus wrote: > I want to write a report where even lines are written with no background and odd lines with a light gray background. A little bit out of the box thinking :-) You could add the lines to a TStringGrid (ColCount := 1) and set the color for the alternating row in OI.

Sorry I haven't understand anything ;-)

TStringGrid? It is a report using LazReport, What has TSringGrid to do with LazReport?
What is OI?

Saludos Santiago A.

Reply by email

Bart
to Santiago A.
PM Santiago A. wrote
TStringGrid? It is a report using LazReport, What has TSringGrid to do with LazReport?

I have no experience with LazReport.
You wrote you would make the report in a memo, I assumed you could do that in a TSTringGrid as well.
It seems, you can not?

What is OI?

The Object Inspector.

Bart

Reply by email

Jesus Reyes A.
to Santiago A.: Hi: I want to write a report where even lines are written with no background and odd…

En Sun, 03 May 2020 11:03:12 -0500, Santiago A. via lazarus

Show quoted text 24 lines
Hi: I want to write a report where even lines are written with no background and odd lines with a light >gray background. The idea is an memo (MemoBackground) in the background of the masterData Band that is gray and I >set visible or invisible, according with the line. I have created a report variable "LineCounter" In the ColumnHeader band (the report has two columns) I have a Script Begin LineCounter:=0; end; In the GorupHeader header I have this script Begin LineCounter:=0; end; In the masterData band Script: begin LineCounter:=LineCounter+1; MemoBackground.visible:=(LineCounter mod 2 = 0); end

Probably the easiest way of doing what you want is using an empty memo object sized to the extent you want for the background row, any other field on the band should be 'above' the background memo (you can just select the background memo and press the 'send to bottom' tool button), any field on the band should be transparent color. Then edit the background memo and use this script:

if [LINE#] mod 2 = 0 then
   FillColor := clGray
else
   FillColor := clWhite;

As written and because the variable Line# starts at 1, the first line will be white.

You can apply this method to any existing report as it doesn't require modifying the source code of your application.

Regards.

Jesus Reyes A.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20200506/55ea7a46/attachment.html>

Reply by email

Santiago A.
to Jesus Reyes A.
Jesus Reyes A. wrote 55 lines
En Sun, 03 May 2020 11:03:12 -0500, Santiago A. via lazarus escribió: Hi: I want to write a report where even lines are written with no background and odd lines with a light gray background. The idea is an memo (MemoBackground) in the background of the masterData Band that is gray and I set visible or invisible, according with the line. I have created a report variable "LineCounter" In the ColumnHeader band (the report has two columns) I have a Script Begin  LineCounter:=0; end; In the GorupHeader header I have this script Begin  LineCounter:=0; end; In the masterData band Script: begin  LineCounter:=LineCounter+1;  MemoBackground.visible:=(LineCounter mod 2 = 0); end Probably the easiest way of doing what you want is using an empty memo object sized to the extent you want for the background row, any other field on the band should be 'above' the background memo (you can just select the background memo and press the 'send to bottom' tool button), any field on the band should be transparent color. Then edit the background memo and use this script: if [LINE#] mod 2 = 0 then   FillColor := clGray else   FillColor := clWhite; As written and because the variable Line# starts at 1, the first line will be white. You can apply this method to any existing report as it doesn't require modifying the source code of your application. Regards. Jesus Reyes A.

Ok I'll try
Nevertheless, that doesn't answer my question: How to use "not-predefined" variables. How can I access to the variable lineCounter?

Saludos Santiago A. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20200507/3295a105/attachment-0001.html>

Reply by email

Graeme Geldenhuys
to Santiago A.: Hi: I want to write a report where even lines are written with no background and odd…
Santiago A. wrote
I want to write a report where even lines are written with no background and odd lines with a light gray background.

Have you considered using the newer FPReport (aka fcl-report) included with FPC? There is a report designer for Lazarus too. It is super simple to implement the alternating colors that you required. Take a look at the fcl-report/demos/ directory and look at the "rptexpressions.pas" unit. All you need to do is assign the alternating colors in the DoBeforePrint() event handler.

eg:

procedure TExpressionsDemo.DoBeforePrint(Sender: TFPReportElement);
begin
  With rpt.Variables.FindVariable('isEven') do
    AsBoolean:=Not AsBoolean;
  if rpt.Variables.FindVariable('isEven').AsBoolean then
    Sender.Frame.BackgroundColor := clLtGray
  else
    Sender.Frame.BackgroundColor := clWhite;
end;

Regards,
Graeme

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ My public PGP key: http://tinyurl.com/graeme-pgp

Reply by email

Santiago A.
to Graeme Geldenhuys
Graeme Geldenhuys wrote 27 lines
On 03/05/2020 5:03 pm, Santiago A. via lazarus wrote: > I want to write a report where even lines are written with no background > and odd lines with a light gray background. Have you considered using the newer FPReport (aka fcl-report) included with FPC? There is a report designer for Lazarus too. It is super simple to implement the alternating colors that you required. Take a look at the fcl-report/demos/ directory and look at the "rptexpressions.pas" unit. All you need to do is assign the alternating colors in the DoBeforePrint() event handler. eg: procedure TExpressionsDemo.DoBeforePrint(Sender: TFPReportElement); begin With rpt.Variables.FindVariable('isEven') do AsBoolean:=Not AsBoolean; if rpt.Variables.FindVariable('isEven').AsBoolean then Sender.Frame.BackgroundColor := clLtGray else Sender.Frame.BackgroundColor := clWhite; end; Regards, Graeme

Yes, in fact I have solved it with a similar way using events in pascal. Nevertheless, that is not the question. Do variables work in LazReport or not? if they do, how?
I have hidden a band and a few tweaks using the reports scripts, that means that I have divided the logic of the report in the scripts in lrf file and in events in the pascal source. If I can't trust that scripts work, I will move everything  to pascal and let the report just for basic graphic design with no script.

Using only pascal events is not the best solution, because I could, for example, change the design of alternate colors of the band to a line division without touching the pascal code and having to generate a new executable.

I still hope that I have misunderstood something about variables, or at least it is known bug.

Saludos Santiago A.

Reply by email