How To…Display a Group Footer on Every Page

Question

“How do I ensure that the group footer will display on every page of my report?”

Solution

This can be helpful if you need a page summary band, similar to the page footer band but snaps to the last detail band.

Use the DetailBand.BeforePrint event to determine if the group will break before space runs out on the page.  If not, manually add the group drawcommands below the last detail line leaving enough space to print.  This will ensure that the group footer prints on every page similar to the Group Header.

Download: GroupFooterOnEveryPage.zip

Sample Delphi code:

procedure TForm1.ppDetailBand1BeforePrint(Sender: TObject);
var
  lbGroupBreak: Boolean;
begin

  if FDrewGroupFooter then
    ppDetailBand1.OutofSpace := True;

  {peek at next record to determine if group is going to break on this page}
  lbGroupBreak := WillGroupBreak;

  if lbGroupBreak then
    begin
      //See the included example of an implementation of this routine.
      DrawGroupFooter(ppReport1.Engine.PrintPosRect.Top);
      
      FDrewGroupFooter := True;
    end;

end;

function TForm1.WillGroupBreak: Boolean;
begin
  Result := CheckNormalGroupBreak;

  if not(Result) then
    Result := CheckSpaceLeftOnPageForGroup;

end;

{@TForm1.CheckNormalGroupBreak

  Check to see if normal group breaking will work the standard way of group breaking}

function TForm1.CheckNormalGroupBreak: Boolean;
var
  lsCurrentValue: String;
  lsNextValue: String;
begin

  Result := False;

  lsCurrentValue := ppReport1.DataPipeline['CustNo'];

  ppReport1.DataPipeline.Next;

  if not(ppReport1.Datapipeline.EOF) then
    begin

      lsNextValue := ppReport1.Datapipeline['CustNo'];

      ppReport1.DatapipeLine.Prior;

      lsCurrentValue := Lowercase(lsCurrentValue);
      lsNextValue := Lowercase(lsNextValue);

      if (lsCurrentValue <> lsNextValue) then
        Result := True;

    end;

end;

{@TForm1.CheckSpaceLeftOnPageForGroup

  If normal group breaking will not force a group break because the group has
  more records then need to check if have space to print the next record and
  also the group  footer on the page.}

function TForm1.CheckSpaceLeftOnPageForGroup: Boolean;
var
  ldRequiredDetailGroupFooterSpaceInInches: Double;
  ldAvailableSpaceInInches: Double;
  liAvailableSpace: Integer;
begin

  Result := False;

  liAvailableSpace := ppReport1.PrinterSetup.PageDef.mmPrintableHeight - ppReport1.Engine.PrintPosRect.Top;

  ldAvailableSpaceInInches := ppFromMMTHousandths(liAvailableSpace, utInches, pprtVertical, ppReport1.Printer);

  ldAvailableSpaceInInches := ldAvailableSpaceInInches - ppFooterband1.Height;

  ldRequiredDetailGroupFooterSpaceInInches := ppDetailBand1.Height + ppGroupFooterband1.Height;

  if (ldRequiredDetailGroupFooterSpaceInInches > ldAvailableSpaceInInches) then
    Result := True;
end;