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

Koenraad Lelong lazarus2 at de-brouwerij.be
Tue Mar 11 10:10:25 CET 2014


op 10-03-14 17:28, Jesus Reyes schreef:
>
>
>> 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.

>
> 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.

>
>>
>> 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




More information about the Lazarus mailing list