Last record of group
Hi
I need to "switch" off (i.e. Set visible property to False or True) a Line object in a master band, but only if the master band record is the last record in a group. Any ideas / suggestions?
Report layout:
Group header band
Master band (<<-- if this is the last record for the current group, set Line object Visible property to False else set it to True)
Any ideas?
TIA
Regan
I need to "switch" off (i.e. Set visible property to False or True) a Line object in a master band, but only if the master band record is the last record in a group. Any ideas / suggestions?
Report layout:
Group header band
Master band (<<-- if this is the last record for the current group, set Line object Visible property to False else set it to True)
Any ideas?
TIA
Regan
Comments
I'd try this:
Set it to be a DoblePass report, first of all.
Then all the following is in the scripts of the report:
Create a global variable to count the number of records, let's say TotalRecs, and one for the current rec, CurrentRecCounter, initialise them with 0.
Then on the OnBeforePrintEvent of your MasterData band you increase the counter IF it's the first pass, or if it's the FINAL pass, then you set the visibility of your line to true or false:
MasterData.OnBeforePrintEvent
begin
if not Engine.FinalPass then
inc(TotalRecs)
else begin
inc(CurrentRecCounter);
if CurrentRecCounter >= TotalRecs then
Line1.visible := false
else
Line1.visible := true;
end;
end;
Alternatively, you can skip the inc(TotalRecs) line and initialise it directly with
TotalRecs := Dataset.recordcount;
I hope it gives you some ideas.
child1.visible := not dataset.eof;
where your line is in the child1 band.
retrieve the recordcount of the dataset store in a variable
when line# variable = recordcount turn off what you want.
Grouping
since you are using grouping you will have to make the report 2 pass store the count in an array
just like storing a total to print in the header, only store the count.
as Anu de Deus has suggested.
Thanks for the help and ideas. It pointed me in the right direction. In my final solution, I followed the "Total in Group header" example somewhat.
Not fully understanding how the variables were being reset in the events, I had to play around initially. I also added a group footer, which I didn't need (so I just set its Visible property to False on the FinalPass - not sure if it needs to be visible for the OnBeforePrint to be called, so left it there for the first pass).
Anyways, below is the code I finally implemented:
var
slGrpList: TStringList;
iGrpRecCount: integer;
iGrpCount: integer;
procedure frxInvoiceOnStartReport(Sender: TfrxComponent);
begin
iGrpRecCount:= 0;
iGrpCount:= 0;
iRecID := 0;
slGrpList:= TStringList.Create;
end;
procedure frxInvoiceOnStopReport(Sender: TfrxComponent);
begin
slGrpList.Free;
end;
procedure GroupFooter1OnBeforePrint(Sender: TfrxComponent);
begin
if not Engine.FinalPass then
begin
List.Add(IntToStr(iGrpRecCount));
iGrpRecCount:= 0;
end;
Inc(iGrpCount);
iRecID := 0;
if Engine.FinalPass then
GroupFooter1.Visible := False;
end;
procedure MasterData11OnBeforePrint(Sender: TfrxComponent);
begin
if not Engine.FinalPass then
begin
inc(iGrpRecCount);
end
else
begin
Inc(iRecID );
if iRecID = StrToInt(List[iGrpCount-List.Count]) then // note this, the iGrpCount variable was always working out to twice the actual list count, hence the subtraction
Line33.visible := false
else
Line33.visible := true;
end;
Anyway, thanks for the suggestions. I got it to work!
Regan
No need 2 pass, no need variable, simple code in one function.
I am not very familiar with FR coding though so I don't know it had bad effect or not...