How to make report inheritance in FastReport.NET

2021-01-29

When you are tasked with creating a large number of reports within one corporate style, you face the problem of duplicating some information, design styles in each report. As a rule, public reports (documents) in a company have the same header with name and contact information. Let's say you have 50 templates with the same header. But the company address changes and you need to open each template in the editor and correct it. But if there are not 50 templates, but 100, it's a real headache.

Avoiding this problem is helped by the inheritance mechanism, where you have a template that can be used in different reports. Changes to this template will appear in all inherited reports.

Report inheritance in FastReport.NET is organized as follows. You start by creating a so-called base report from which you inherit others. This report should contain a template with information common to all inherited reports. For example, it can be a header with the company details.

As mentioned above you can modify the base report template and then it will change in all the legacy reports. But you can also edit the information from the base report in the legacy report. These changes will only be saved in that particular report.

But what if you have modified an object from the base report in an inherited report and then modified the same object in the base report. In this case, the changes from the base report will be applied to that object, but only those that do not overlap with the changes in the legacy report. For example, if you change the font in a text object in an inherited report, and then set bold spelling for the same object in the base report, both changes will be applied. And if you change the font in the base report too, it will not be reflected in the legacy report, as it has already been changed in it.

It is also worth bearing in mind the restrictions on inheriting the report. You may not:

  1. Delete and move the base report, otherwise all inherited reports will be damaged.
  2. Inherit a report from another inherited report. That is, multiple inheritance is not allowed.
  3. Use script, report parameters, "Table" object and "Matrix" object in the base report.

Now let's look at an example of creating an inherited report. First you need to create a basic report.

For example, it will contain a report template with the title:

FastReport.NET

Save this report with a name containing base, so that it is easier to find amongst the other report templates.

To create a legacy report you need to use the legacy report wizard. This is available either in the welcome screen or in the new report window (File->New):

FastReport.NET

The Legacy Report Wizard will only offer you one action - select the base report using the Open File dialog box. Select the base report you have previously created. All elements of the report have a padlock icon. This means that they are inherited from the base report. 

FastReport.NET

Newly added objects will no longer have this icon. Add a data source to our report and place the fields on the "Data" band. For example, you can use the demo data source nwind.xml from FastReport.NET:

FastReport.NET

From the data source we select the Categories and Products tables. These tables are linked by key and so we can easily create a Master-Detail report:

FastReport.NET

As you can see, the added data fields and the Header and DetailData bends do not have a padlock icon. You can always tell the difference between the legacy report objects and the baseline report by this feature.

This way you can create a large number of reports in a single style, and then easily edit them all by changing only the basic template.

August 12, 2024

How to build and install the Postgres plugin in FastReport .NET

This article describes how to connect to the database using the FastReport .NET plugin for the report designer from Visual Studio via the NuGet server.
August 08, 2024

How to install FastReport .NET and its components on Windows

Step-by-step instructions for online and manual installation via the FastReport registration code.NET and its components in Windows.
July 26, 2024

Updating HTMLObject as a plugin for FastReport .NET

Detailed instructions for using the new HTMLObject plugin, which uses splitting DOM HTML into FastReport report objects.
Fast Reports
  • 800-985-8986 (English, US)
  • +4930568373928 (German)
  • +55 19 98147-8148 (Portuguese)
  • info@fast-report.com
  • 901 N Pitt Str #325 Alexandria VA 22314

© 1998-2024 Fast Reports Inc.