delphireportbuilder

How to conditionally format ReportBuilder field in Detail band depending on the other fields in then Detail band?


My DBText5 contains 0 or 1 and I would like to format DBText3 depending on DBText5 - I am using code (How set font properties in calculated field using Digital-Metaphors Report Builder RAP):

if (DBText5.FieldValue=1) then begin
  DBText3.Font.Bold := True;
end;

Both, DBText3 and DBText5 reside in Detail band. I have tried to put this code in the following events (of course I checked that only one event is active at each given time):

DBText3.OnPrint
DetailBand.OnBeforePrint
CustomVariableOnDetailsBand.Calculate

But in each case the DBText3 appears bold in all rows of the report. My intention is to make DBText3 bold in only those rows whose hase DBText5=1. Which event should I use or what other adaptations should I make?

Digital Metaphors own solution is to use Band.OnBeforePrint https://www.digital-metaphors.com/forums/discussion/9962/conditional-format but Detail.OnBeforePrint is not working form, as I said.

Additional Info: As suggested by the accepted answer - one should implement else clause as well.


Solution

  • I created a quick test project and confirmed that this works.

    I'm using Report Builder 19, Build 76, and Delphi 10.2.

    procedure TForm1.ppDetailBand1BeforePrint(Sender: TObject);
    begin
      if DBText5.fieldvalue = 20  then
        DbText5.Font.Style := [fsBold]
      else
        DbText5.Font.Style := [];
    end;
    

    You need to set the style for both the true and false condition.

    Since you're using RAP, you can use

    if DbText5.Fieldvalue = 1 then
      DbText5.Font.Bold := true
    else
      DbText5.Font.Bold := false;