Have an amazing solution built in RAD Studio? Let us know. Looking for discounts? Visit our Special Offers page!
CodeDelphiTech Partner

How To Create Your Own Components For The FastReport Dialog

Creating your own components for the FastReport dialog

When creating a report, it is important not only to make a nice printable form that will display the data the user needs but also a convenient pre-print dialog, where the user can set the parameters to generate the report.

The FastReport preprint dialog already contains a number of components, for example, Label, Edit, Button, Memo. But sometimes this is not enough and you have to create your own dialog components for FastReport. In fact, they are analogs to the usual Delphi components that can be used in FastReport dialog forms. This article will talk about creating this component using IDE Software: Delphi.

For more information, we recommend reading the FastScript documentation and the FastReport VCL manuals for developers and software specialists.

To display data from the database, this article uses the DBGridEh component from the EhLib VCL library L, which will be integrated into the FastReport dialog. Delphi 10.4.2 was used as a development environment, but everything described below will be suitable for any other Delphi starting from version 7 (adjusted for the version).

Let’s create a new package (dpk) and name it frxDBGridEh27. Add to it a new file frxDBGridEhControl.pas, which will serve as the basis for our grid.

We will declare a component in this file for registration in Delphi:

Creating your own components for the FastReport dialog report parameters screen

We begin to describe the TfrxDBGridEh component, which will be created from the base dialog class TfrxDialogControl. In fact, we will re-declare the properties of the base DBGridEh component into a component to use in FastReport. You can re-declare not all properties, methods, event handlers, but only those that are needed for work.

In the private section, I recommend paying special attention to the following:

The rest of the methods in this section are needed to read/write the DBGridEh properties, which we will set in frxDBGridEh in the FastReport dialog. These methods are some kind of intermediaries between frxDBGridEh and DBGridEh.

The protected section contains three system overridden methods for handling events occurring in the FastReport designer: deleting a data source that is already connected to the grid, setting methods for reading/writing grid columns to the fr3 report template file, and processing in order to specify the component name.

The public section contains methods such as the constructor and destructor of our component. Among other things, you need to create a basic (internal) DBGridEh inside the constructor, a data connection interface (DataSource) for connecting to the grid, and event handlers.

We set the description of our grid, which will be visible in the FastReport designer, as well as additional methods for saving the collection of grid columns as XML to the fr3 report template. The rest of the methods and properties of this section are needed to programmatically use in the report script.

The published section contains properties and event handlers that will be visible in the object inspector of the FastReport designer and which can also be set in the report script.

Note the initialization section, which states:

  1. description of grid event handlers for different programming languages of the report script;
  2. registration of the grid in the palette of FastReport components.

Now let’s add another frxDBGridEhColumnsEditor module to our package (code plus form). This module uses the capabilities of FastReport for visual work with collections in the designer. At this stage, we create a grid column editor similar to the Delphi column editor. In the initialization section, we register this editor in the FastReport environment for visual editing of a set of frxDBGridEh columns.

Creating your own components for the FastReport dialog 2

This module has two classes: TfrxDBGridEhColumnsEditorForm — the form of the column editor with the necessary functionality and TfrxDBGridEhEditor for connecting (calling) our editor from the FastReport designer.

Next, we add another frxDBGridEhEditor file to the package where we will place the editors of the grid properties. First of all, let’s add a property for editing columns by linking Columns: TDBGridColumnsEh to our editor.

Now we create an editor for selecting a data source. We made the SetDataSet and SetDataSetName methods more universal than, for example, in the standard frxDBLookupComboBox, that’s why we can use both TDataSet heirs (Delphi) and TfrxDBDataset heirs (FastReport) as a data source. In the end, we add an editor to select a field for a grid column.

The last module we add to our package is the frxDBGridEhRTTI file, where we implement the TFunctions = class (TfsRTTIModule), inside which we add classes, methods, and properties for the report script (FastScript) that we want to programmatically call from it (for example, methods for program addition/removal of columns and for saving the state of grid columns).

The final step is to create the frxDBGridEh.dcr file with an icon of our component. This is necessary to display Delphi components and the frxDBGridEh.res file in the palette with an icon of our component for displaying the FastReport component in the palette.


For more blog posts about FastReport click here for a dynamic search: https://blogs.embarcadero.com/?s=FastReport


Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial   Upgrade Today

   Free Delphi Community Edition   Free C++Builder Community Edition

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

IN THE ARTICLES