How To…Calc a Dynamic Detail Height

Question

“How do I calculate the height of each dynamic detail band’s height as the report is generating?”

Solution

Use the DetailBand.BeforeGenerate to find the top of each band and the DetailBand.AfterPrint event to find the bottom and calculate the height.  Do this during the first pass of the report to find each height before the report actually prints.

Download: DynamicDetailHeight.zip

Sample Delphi code:

uses
  ppUtils, ppTypes;

procedure TForm1.ppDetailBand1BeforeGenerate(Sender: TObject);
begin
  FTop := ppReport1.Engine.PrintPosRect.Top;

  FTop := ppFromMMThousandths(Round(FTop), ppReport1.Units, pprtVertical, ppReport1.Printer);
end;

procedure TForm1.ppDetailBand1AfterPrint(Sender: TObject);
var
  ldHeight: Double;
begin

  FBottom := ppReport1.Engine.PrintPosRect.Bottom;

  FBottom := ppFromMMThousandths(Round(FBottom), ppReport1.Units, pprtVertical, ppReport1.Printer);

  ldHeight := FBottom - FTop;

  ShowMessage(FloatTOStr(ldHeight));

end;