[Lazarus] How to color a field in a LazReport ?

Jesus Reyes jesusrmx at yahoo.com.mx
Mon Mar 10 17:28:37 CET 2014



> El Lunes, 10 de marzo, 2014 9:10:39, Koenraad Lelong <lazarus2 at de-brouwerij.be> 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. 

  
> 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

> 
> 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
> Lazarus at lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>




More information about the Lazarus mailing list