Search code examples
delphireportingfastreport

How to not display zero value and shift it in FastReport


I have one question in FastReport. I need to make a report in which I see only non zero value. For example I have masterdata which fill data from sql query. On masterdata I put 3 description and value fields. Its look like this:

[DATA."DESC1"] DESCRIPTION1 [DATA."VALUE1"] 100
[DATA."DESC2"] DESCRIPTION2 [DATA."VALUE2"] 0
[DATA."DESC3"] DESCRIPTION3 [DATA."VALUE3"] 50

and I want to see on report

DESCRIPTION1 100
DESCRIPTION3 50

but now I see view like this

DESCRIPTION1 100

DESCRIPTION3 50

I do not want to see blank position, I need to shift third position on second position because the second value is null. Of course in my SQL query there is much more fields with value. I try to find some loop that solve my problem but I didn`t found. I try to use properties Visible or ShiftMode but it not help for this. Mayby someone knows how to solve this problem in FastReport. Please help me.


Solution

  • As an additional option, you may always use the OnBeforePrint event (in this case for the MasterData band) and organize your logic:

    Example, when the DATA."VALUE2" is 0:

    procedure MasterData1OnBeforePrint(Sender: TfrxComponent);
    var
       top: Extended;                                     
    begin
       top := 0;                           
       // TfrxMemoView 1                                                    
       Memo1.SetBounds(Memo1.Left, top, Memo1.Width, Memo1.Height);
       top := top + Memo1.Height;
       // TfrxMemoView 2                                                       
       if (<DATA."VALUE2"> = 0) then begin                                      
          Memo2.Visible := False;                                                      
          end
       else begin
          Memo2.Visible := True;                                                      
          Memo2.SetBounds(Memo2.Left, top, Memo2.Width, Memo2.Height);
          top := top + Memo2.Height;
       end;
       // TfrxMemoView 3                                                       
       Memo3.SetBounds(Memo3.Left, top, Memo3.Width, Memo3.Height);
       top := top + Memo3.Height;
    end;
    

    Example, when the DATA."VALUE1" is 0:

    procedure MasterData1OnBeforePrint(Sender: TfrxComponent);
    var
       top: Extended;                                     
    begin
       top := 0;                           
       // TfrxMemoView 1                                                    
       if (<DATA."VALUE1"> = 0) then begin                                      
          Memo1.Visible := False;                                                      
          end
       else begin
          Memo1.Visible := True;                                                      
          Memo1.SetBounds(Memo1.Left, top, Memo1.Width, Memo1.Height);
          top := top + Memo1.Height;
       end;
       // TfrxMemoView 2                                                       
       Memo2.SetBounds(Memo2.Left, top, Memo2.Width, Memo2.Height);
       top := top + Memo2.Height;
       // TfrxMemoView 3                                                       
       Memo3.SetBounds(Memo3.Left, top, Memo3.Width, Memo3.Height);
       top := top + Memo3.Height;
    end;