jeffers
jeffers

Reputation: 145

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.

Upvotes: 1

Views: 3914

Answers (4)

Zhorov
Zhorov

Reputation: 29973

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;

Upvotes: 1

Marc Guillot
Marc Guillot

Reputation: 6455

You can also place 3 different MasterData bands (or more), all of them linked to DATA. So you can insert each Memo in their own MasterData, and use OnBeforePrint to hide that MasterData when its particular content is empty.

Upvotes: 0

Marc Guillot
Marc Guillot

Reputation: 6455

It would be trivial if your query returns those values as multiple rows instead of multiple columns.

Your current query must be something like :

select 'Name' as Desc1, Name as Value1, 'Surname' as Desc2, Surname as Value2, 'Address' as Desc3, Address as Value3, ....
from MyTable
where Id = X

You can change it to :

select 'Name' as Desc, Name as Value
from MyTable
where Id = X
union
select 'Surname' as Desc, Surname as Value
from MyTable
where Id = X
union
select 'Address' as Desc, Address as Value
from MyTable
where Id = X
...

So now to hide the empty values on FastReports is as easy as filtering them on your dataset before executing the report.

Upvotes: 0

JacalarRick
JacalarRick

Reputation: 153

In the properties for the MasterData band, make sure Stretchable is set to True and Stretch Mode is set to Actual Size.

Upvotes: 0

Related Questions