Sign in Join

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

Mailing lists / lazarus / 2014-03

How to color a field in a LazReport ?

5 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

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

Koenraad Lelong

Hi,

I'm trying to make the background of dbfield in a LazReport different. I tried using the userds example, but it does not work. This is what I wrote :

procedure TDataModule1.frReport1EnterRect(Memo: TStringList; View: TfrView);
begin
if FNegative then
  View.FillColor:=clRed
else
   View.FillColor:=clWhite;
end;
procedure TDataModule1.frReport1GetValue(const ParName: String;
   var ParValue: Variant);
begin
Append(OutFile);
writeln(OutFile,ParName);
CloseFile(OutFile);
if ParName='qrySamenVatting."VERSCHIL"' then
   FNegative:=qrySamenVattingVERSCHIL.AsFloat<0.0
else
   FNegative:=false;
end;

This colors the wrong field. After some debugging I found EnterRect is fired before GetValue. So, how can I modify the color based on the value ?

Koenraad.

Jesus Reyes
to Koenraad Lelong
Show quoted text 6 lines
El Lunes, 10 de marzo, 2014 9:10:39, Koenraad Lelong escribi?: > Hi, I'm trying to make the background of dbfield in a LazReport different. I tried using the userds example, but it does not work. This is what I wrote :

Have you tried

procedure TDataModule1.frReport1EnterRect(Memo: TStringList; View: TfrView); begin ?
? ? if Dataset.FieldByName('VERSCHIL').asFloat<0.0 then
? ? ? ?View.FillColor := clRed
? ? else
? ? ? ?View.FillColor := clWhite;
end;

?

Another way is, as shown in UserDs example, using a Script, You can make a script var 'Negative', which value is updated in OnGetValue, just like FNegative below, the difference would be that 'Negative' is a script var and in your example FNegative is some data module field or property. In the UserDS sample that would be something similar to variable 'I', for example.?

?

Show quoted text 12 lines
procedure TDataModule1.frReport1GetValue(const ParName: String; ?? var ParValue: Variant); begin Append(OutFile); writeln(OutFile,ParName); CloseFile(OutFile); if ParName='qrySamenVatting."VERSCHIL"' then ?? FNegative:=qrySamenVattingVERSCHIL.AsFloat<0.0 else ?? FNegative:=false; end;

Used that way, the memo field's script would be something like:

Begin
? if Negative then
? ? FillColor := clRed
? else
? ? FillColor := clWhite;
End
Show quoted text 13 lines
This colors the wrong field. After some debugging I found EnterRect is fired before GetValue. So, how can I modify the color based on the value ? Koenraad. -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Koenraad Lelong
to Jesus Reyes
Jesus Reyes wrote 19 lines
> El Lunes, 10 de marzo, 2014 9:10:39, Koenraad Lelong escribi?: >> Hi, > Have you tried > > procedure TDataModule1.frReport1EnterRect(Memo: TStringList; View: TfrView); > begin > if Dataset.FieldByName('VERSCHIL').asFloat<0.0 then View.FillColor := clRed else View.FillColor := clWhite; > end; > ?

Now I have ;-). It does not work like expected because (I think) Dataset contains a whole record. The code says : if the field 'VERSCHIL' of the current record contains a negative value paint the box of the current field red. But that's true for all fields in the record.

I added :
if Memo.Text='[qrySamenVatting."VERSCHIL"]'#13#10 then
if Dataset.FieldByName('VERSCHIL').asFloat<0.0 then View.FillColor := clRed else View.FillColor := clWhite;

This works as I expected.

Show quoted text 26 lines
Another way is, as shown in UserDs example, using a Script, You can make a script var 'Negative', which value is updated in OnGetValue, just like FNegative below, the difference would be that 'Negative' is a script var and in your example FNegative is some data module field or property. In the UserDS sample that would be something similar to variable 'I', for example. > procedure TDataModule1.frReport1GetValue(const ParName: String; > var ParValue: Variant); > begin > > Append(OutFile); > writeln(OutFile,ParName); > CloseFile(OutFile); > if ParName='qrySamenVatting."VERSCHIL"' then > FNegative:=qrySamenVattingVERSCHIL.AsFloat<0.0 > else > FNegative:=false; > end; Used that way, the memo field's script would be something like: Begin if Negative then FillColor := clRed else FillColor := clWhite; End

When will that script be executed ? Before or after the EnterRect ? Before is OK, after, like GetValue, is too late.

Show quoted text 7 lines
> > This colors the wrong field. After some debugging I found EnterRect is > fired before GetValue. So, how can I modify the color based on the value ? > > > Koenraad.

Thanks anyway, I'm a step further. Now getting a crosstab to work.

Koenraad

Koenraad Lelong
to Koenraad Lelong: I'm trying to make the background of dbfield in a LazReport different. I tried using the…
Koenraad Lelong wrote
Hi, I'm trying to make the background of dbfield in a LazReport different.

Hi,

Just found out how to do this :

In the report-editor there is a button 'Highlight Attributes'. I found this by chance by having my mouse stay over it for some time. There you can enter something like 'VALUE<0' and select some attributes.

One remark : on Linux the attributes-form is cut. Not all information is shown. On Windows, you can see all.

Koenraad.