Conditional highliting.

edited 8:51PM in FastReport 4.0
Hello.

I'm using Delphi2010 and FR4.0, I'm not using .NET.
Is there a way to add more than one condition in highliting detail field?
As far as I can see in Report Designer I can pick only one conditiong to color one field...

I want to make a few conditions to one cell depending on value.

Thanks

Comments

  • hsmhsm
    edited 8:51PM
    oyci3c wrote: »
    Hello.

    I'm using Delphi2010 and FR4.0, I'm not using .NET.
    Is there a way to add more than one condition in highliting detail field?
    As far as I can see in Report Designer I can pick only one conditiong to color one field...

    I want to make a few conditions to one cell depending on value.

    Thanks


    Use the OnBeforePrint event of the master band (or wherever the memo is)
    In the code section of the report write your conditions.
    Don't forget to include the default if no condition is met.
    Otherwise the memos that do not meet the condition, but follow one that did, will have the same colour as the one that did.

    example code colouring red if < 0, yellow if = 0, red if = 99 and white if no condition met is shown below.
    procedure MasterData1OnBeforePrint(Sender: TfrxComponent);
    begin
    MemoFieldToTest.color := clWhite;     //default,  otherwise it will have the same colour as the last met condition    
    if <frxDBDataset1."FieldToTest"> < 0 then
        MemoFieldToTest.color := clred;
    
    if <frxDBDataset1."FieldToTest"> = 0 then
        MemoFieldToTest.color := clYellow;
     
    if <frxDBDataset1."FieldToTest">  = 99 then
         MemoFieldToTest.color := clGreen;
    //etc 
    end;
    
  • edited 8:51PM
    Working like a charm, thanks.
    wrote:
    Don't forget to include the default if no condition is met.
    Otherwise the memos that do not meet the condition, but follow one that did, will have the same colour as the one that did.

    Yep, that was my mistake ;-)
  • edited March 2014
    Even with setting default condition in the beginning it's taking last condition for all rows.
           frxDBDatasetDetaildata_wejscia.font.color := clBlack;         
                   if (<frxDBDatasetDetail."nazwa_wejscie"> = 'Niedziela') and (<frxDBDatasetDetail."czas"> = '') then              
                           frxDBDatasetDetaildata_wejscia.font.color := clBlue;
                   if (<frxDBDatasetDetail."data_wyjscia"> = '') and (<frxDBDatasetDetail."czas"> = '') then              
                           frxDBDatasetDetaildata_wejscia.font.color := clRed;
    
  • hsmhsm
    edited March 2014
    Use a nested IF then. Its OK for a smallish number of tests.
    and this code should be in the onBeforePrint of the detail band (as you are testing frxDBDatasetDetail."nazwa_wejscie")
    if (<frxDBDatasetDetail."nazwa_wejscie"> = 'Niedziela') and (<frxDBDatasetDetail."czas"> = '') then              
            frxDBDatasetDetaildata_wejscia.font.color := clBlue
     else
        if (<frxDBDatasetDetail."data_wyjscia"> = '') and (<frxDBDatasetDetail."czas"> = '') then              
                frxDBDatasetDetaildata_wejscia.font.color := clRed
        else
                frxDBDatasetDetaildata_wejscia.font.color := clBlack;
    
  • edited 8:51PM
    hsm wrote: »
    Use a nested IF then. Its OK for a smallish number of tests.
    and this code should be in the onBeforePrint of the detail band (as you are testing frxDBDatasetDetail."nazwa_wejscie")
    if (<frxDBDatasetDetail."nazwa_wejscie"> = 'Niedziela') and (<frxDBDatasetDetail."czas"> = '') then              
            frxDBDatasetDetaildata_wejscia.font.color := clBlue
     else
        if (<frxDBDatasetDetail."data_wyjscia"> = '') and (<frxDBDatasetDetail."czas"> = '') then              
                frxDBDatasetDetaildata_wejscia.font.color := clRed
        else
                frxDBDatasetDetaildata_wejscia.font.color := clBlack;
    

    Yeah got it figured out with nested IF, thanks for your effort and help!

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.