Orphan Control for Groups

Tom Nesler <[email protected]> Tue, 10 Sep 2002 09:00:18 -0700 (PDT)
Newsgroups gmane.comp.lang.delphi.quick-reports
Message-ID <[email protected]>
Hello!

Has anyone figured out how to prevent printing of a group of records in
QR if there is not enough space to print all the records and the Group
footer?

QRQA295 talks about this but I cannot get the recommended workaround to
work.

Here is the question and answer given.  Please comment if you see what
is wrong here:

Q:  Is there a property for QRDBText to tell it *not* to split itself
across pages? (i.e. widow/orphan protection.)

A:  Support for a "widow/orphan" feature will part of the 3.0 release,
due out early next year.  You can provide some of it's functionality
with the current release with some minor coding.
First, add the following declarations to the under private in your
report form declaration:

  TfrmReport = class(TForm)
  [extra deleted]
  private
    { Private declarations }
    function GetQRAvailableSpace: integer;
    property QRAvailableSpace: integer read GetQRAvailableSpace;

Then define the function:
function TfrmReport.GetQRAvailableSpace: integer;
begin
  with QuickRep1 do
    if Page.Orientation = poPortrait then
      result := round(QRPrinter.PaperLength - Page.BottomMargin -
PageFooterBand1.Size.Length - CurrentY)
    else
      result := round(QRPrinter.PaperWidth - Page.BottomMargin -
PageFooterBand1.Size.Length - CurrentY);

end;

This assumes a footer band with no child bands.  To see how to check
child band size, see the actual available space function in the
quickrpt unit.

To use this function to prevent a group band from being orphaned, call
it from the BeforePrint event of the group band like the following:

procedure TfrmQRProd.QRGroupCustomerBeforePrint(Sender: TQRCustomBand;
  var PrintBand: Boolean);
begin
  { Set your PrintBand code here if needed }
  if PrintBand then
  begin
    // Force a new page if not enough room for next detail band
    if QRAvailableSpace < round(Sender.Size.Length +
QRGroupCustomer.Size.Length + DetailBand1.Size.Length) then
      Sender.ParentReport.NewColumn;
  end;
end;

This will force a new page if there is not enough room for a detail
band after the group band.
**********************End of Quote ************************

It seems like it is not able to calculate correctly if there are more
than one Detail line to be printed but I am just guessing here.

Also, they talk about a fix in version 3.0.  I have version 3.07.  Did
this get fixed in 3.5X?

Thanks in advance!




=====
Tom Nesler

Live Long...Code Well... and Prosper! V

__________________________________________________
Yahoo! - We Remember
9-11: A tribute to the more than 3,000 lives lost
http://dir.remember.yahoo.com/tribute