How To…Align the Group Footer for Every Column

Question

“How do I line up the group footer bands when using multiple columns and the amount of records in each group is different?”

Solution

This can be done by copying the draw commands in the existing group footers then moving them to the proper position on the page lined up with the lowest group footer.  Use the OnDrawCommandCreate event of the components inside the group footer to save them for each column.  Then use the OnEndPage event of the report to line the components up with eachother.

Download: ColumnsWGroupFootersAligned.zip

Sample Delphi code:

procedure TForm1.FormCreate(Sender: TObject);
begin
  FFooter1DrawCommands := TList.Create;
  FFooter2DrawCommands := TList.Create;

end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  FFooter1DrawCommands.Free;
  FFooter2DrawCommands.Free;

end;


procedure TForm1.ppReport1StartPage(Sender: TObject);
begin

  // clear the draw command lists
  FFooter1DrawCommands.Clear;
  FFooter2DrawCommands.Clear;

end;

procedure TForm1.ppReport1EndPage(Sender: TObject);
var
  liIndex: Integer;
  lDrawCommand1: TppDrawCommand;
  lDrawCommand2: TppDrawCommand;
begin

  // align group footer draw commands
  for liIndex := 0 to FFooter1DrawCommands.Count-1 do
    begin
      lDrawCommand1 := TppDrawCommand(FFooter1DrawCommands[liIndex]);
      lDrawCommand2 := TppDrawCommand(FFooter2DrawCommands[liIndex]);

      // adjust to max top
      if lDrawCommand1.Top > lDrawCommand2.Top then
        lDrawCommand2.Top := lDrawCommand1.Top
      else
        lDrawCommand1.Top := lDrawCommand2.Top;

    end;

end;

procedure TForm1.GroupFooterDrawCommandCreate(Sender, aDrawCommand: TObject);
begin

  // this event-handler is assigned to the OnDrawCommandCreate event of each
  //  object in the group footer band

  // the event fires each time an object prints on a page. The aDrawCommand
  // parameter contains a TppDrawCommand descendant generated by the
  // Label, Shape, or DBText

  if ppReport1.CurrentColumn = 1 then
    FFooter1DrawCommands.Add(aDrawCommand)
  else
    FFooter2DrawCommands.Add(aDrawCommand)

end;