Nested Reports (Subreports)
Nested Reports (Subreports)
Sometimes very complex report are needed which contain blocks of additional data inserted at particular points in the design. Although many of these reports can be designed using an arrangement of FastReport bands, sometimes it just becomes too complicated. In these circumstances it is necessary to use the “Subreport” object
.
When a “Subreport” object is inserted into a design FastReport automatically adds a new page, which is connected to the “Subreport”. Such a nested report resembles a multi-page report in terms of design structure. The only difference is that the nested report is displayed in a specific location on the basic design page, and not after it. When this report is output, as soon as the “Subreport” object is encountered the report engine outputs the connected subreport page in its entirety. After that output continues with the rest of the basic design page.
Further “Subreport” objects can be inserted into a subreport design page, so increasing the depth of nesting. An example of a nested report can be found on the report '3C0 - Travel Management Report' that is in the program menu 'Personnel | Travel Management | Reports'.
It is worth noting that FastReport’s ability to use subreports enables deep nesting of data. Remember that the number of data levels in FastReport is limited to only six when Detail data bands are used instead of the "Subreport" object.
Side-by-Side Subreports
Two or more “Subreport” objects can be placed side-by-side on the same data band:

This design allows reports where the data output of each “Subreport” has varying lengths of rows/records, or varying heights or degree of stretching:

As illustrated, FastReport continues to output the basic design page only after the longest "Subreport" has finished. The 'Vertical Alignment' property can also be used to adjust “Text” object alignment within each subreport.
Limitations on Use of Subreports
Since subreports are placed on the basic design page, they cannot contain any of the following bands: “ReportTitle/ReportFooter”, “PageTitle/PageFooter/PageBackground” or “ColumnTitle/ColumnFooter”. If any of these bands are placed on a nested report page they will not be recognised. For the same reason there is no point in changing any nested report page options, as the options of the basic report page override those of any nested pages.
Do not place objects below the "Subreport" object:

If this is done then the objects created in the subreport will overlay everything placed below the subreport object on the main design page, and the output will be something like this:

To display objects below or after a nested report, use a child band:

This method is also used when several Subreports must be placed one below the other. Use a child band for each Subreport and chain them together, setting the child property of Child1 to Child2, and so on.
PrintOnParent Option
The "Subreport" object has a "PrintOnParent" property which can sometimes be useful. This property is False by default.
Usually a subreport is output as a set of bands on the basic report page. When this is so, the height of the parent band containing the "Subreport" object is not controlled by the bands in the subreport, i.e. it cannot be stretched. If the subreport "PrintOnParent" property is set to True, either in the object inspector or the context menu, the objects in the subreport are physically printed on the band which contains the "Subreport" object. This band can be made to stretch and can have stretched objects placed on it:
