Home General

Help to extend the ReportHeightCalculator unit in order to sum heights of all subreports inside them

Hello

I'm using latest trial version of RB Enterprise, one of the main goals is to design Reports on a Windows Application and then view it on an iOS/Android devices.

I designed the next POS Receipt

image

I use one of your tutorials named "CalculateReceiptPageHeight" in order to solve the report paper height, however this sample use the routine "ReportHeightCalculator" wich NOT sums all the subreports inside bands as you can see in the red circle of the picture above.

Can you please help me to extend the TppReportHeightCalculator class in order to sum all the subreports inside them?

Here's the unit take a look at the "SumTheHeights" function:

-------------------------------------

unit ReportHeightCalculator;

interface

uses
ppReport;

type

TppReportHeightCalculator = class
private
FDetailStopPosition: Integer;
FUsedHeight: Integer;
FReport: TppReport;

procedure SetVisibleBands(aReport: TppReport; aVisible: Boolean);
function SumTheHeights: Double;
procedure DetailBandAfterPrintHandler(Sender: TObject);
procedure ReportEndPageHandler(Sender: TObject);

public
constructor Create;

function CalculatePageHeight(aReport: TppReport): Double;

end;

implementation

uses
ppDevice,
ppTypes,
ppUtils;

constructor TppReportHeightCalculator.Create;
begin
FDetailStopPosition := 0;
FUsedHeight := 0;
FReport := nil;
end;

function TppReportHeightCalculator.CalculatePageHeight(aReport: TppReport): Double;
var
lDevice: TppDevice;
begin

lDevice := TppDevice.Create(nil);

try

FReport := aReport;

FUsedHeight := 0;

{connect calc events}
SetVisibleBands(FReport, False);

FReport.OnEndPage := ReportEndPageHandler;
FReport.DetailBand.AfterPrint := DetailBandAfterPrintHandler;

lDevice.PageSetting := psAll;
lDevice.Publisher := FReport.Publisher;

FReport.PrintToDevices;
FReport.Reset;

finally
SetVisibleBands(FReport, True);

FReport.OnEndPage := nil;
FReport.DetailBand.AfterPrint := nil;

lDevice.Free;
end;

Result := SumTheHeights;

end;


function TppReportHeightCalculator.SumTheHeights: Double;
begin

Result := ppFromMMThousandths(FUsedHeight, FReport.Units, pprtVertical, FReport.Printer);

if (FReport.TitleBand <> nil) then
Result := Result + FReport.TitleBand.Height;

if (FReport.SummaryBand <> nil) then
Result := Result + FReport.SummaryBand.Height;

if (FReport.HeaderBand <> nil) then
Result := Result + FReport.HeaderBand.Height;

if (FReport.Footerband <> nil) then
Result := Result + FReport.FooterBand.Height;

end;

procedure TppReportHeightCalculator.SetVisibleBands(aReport: TppReport; aVisible: Boolean);
begin

if (aReport.TitleBand <> nil) then
aReport.TitleBand.Visible := aVisible;

if (aReport.SummaryBand <> nil) then
aReport.SummaryBand.Visible := aVisible;

if (aReport.HeaderBand <> nil) then
aReport.HeaderBand.Visible := aVisible;

if (aReport.Footerband <> nil) then
aReport.Footerband.Visible := aVisible;

end;

procedure TppReportHeightCalculator.ReportEndPageHandler(Sender: TObject);
begin
FUsedHeight := FUsedHeight + FDetailStopPosition;
end;

procedure TppReportHeightCalculator.DetailBandAfterPrintHandler(Sender: TObject);
begin
FDetailStopPosition := FReport.Engine.PrintPosRect.Top;
end;

end.

-------------------------------------

Thanks a lot

Comments

Sign In or Register to comment.