Skip to main content
All docs
V26.1
  • Embed a Report Viewer in a Non-Modal Form, Page, or User Control (Tabbed MDI) Using a FireDAC DataSet

    • 9 minutes to read

    This tutorial creates a Tabbed MDI (multiple-document interface, similar to a modern browser UI) application where a VCL Report Viewer (TdxReportControl) component is placed on a non-modal child form. Each tab allows users to preview the same parameterized report layout/template populated with different data that FireDAC components load from a relational database.

    Tip

    This tutorial uses a DevExpress JSON-based dataset connection component to load data from a sample SQLite database and a SQL parameter defined in the FireDAC dataset (TFDQuery) to filter the data.

    The following related tutorial implements the same UI/UX with similar performance and demonstrates the same data loading and shaping scenario using report and SQL parameters configured at the TdxReportControl component level:

    Read Tutorial: A Report Viewer in a Tabbed MDI (SQL Database)

    VCL Reports: A DevExpress Report Control-Powered Multi-Document Interface App


    Sample SQLite Database

    This guide uses the following SQLite database shipped with compiled DevExpress VCL demos:

    Tip

    %PUBLIC%\Documents\DevExpress VCL Demos\MegaDemos\Product Demos\ExpressReports\Data\nwind.db

    Download: Compiled VCL Demos

    Step 1 — Create & Configure a RAD Studio Project

    Create a new Delphi or C++Builder Project with two forms – main (for UI element management components and a FireDAC connection) and child (for TdxReportControl and data connection components).

    Main Form

    Place the following components on the form (using the Tool Palette):

    DevExpress Components

    TdxBarManager
    Creates and manages a Ribbon or Toolbar UI in an application.
    TdxTabbedMDIManager
    Allows you to arrange MDI child forms into a tabbed UI (similar to modern web browser apps).

    FireDAC Component

    TFDConnection
    A standard component designed to establish a connection to a database management system.

    VCL Reports: The Main Form with Required Components

    Child Form

    Add a child form and place the following components on the form (using the Tool Palette):

    DevExpress Components

    TdxReportControl
    Allows users to view, print, and export report documents.
    TdxBackendDataConnectionManager
    Manages all data sources for all reports in your application.

    Select the TdxReportControl component and set its Align property to alClient.

    FireDAC Components

    TFDQuery
    A dataset component designed to execute SQL queries.
    TDataSource
    An interface component designed to connect datasets and data-aware components/controls on a form.

    VCL Reports: The Child Form with Required Components

    Step 2 — Configure FireDAC & Data Connection Components

    FireDAC Connection

    Switch to the main form, right-click the TFDConnection component, and select Connection Editor… to configure the database connection:

    1. Select SQLite in the Driver ID combo box.
    2. Click the folder icon for the Database parameter to display the Open File dialog and select the sample SQLite database file.
    3. Click Test to check if the sample SQLite database (nwind.db) is accessible.
    4. Leave the Password field empty and click OK in the FireDAC Login dialog to ensure that the connection is established successfully.
    5. Click OK to close the Connection Editor… dialog.

    VCL Reports: The FireDAC Connection Editor

    FireDAC Query — Configure SQL Query & Filter Parameter

    1. Switch to the child form, double-click the TFDQuery component to display the FireDAC Query Editor dialog.
    2. Paste the following SQL query into the command editor:

      select [Customers].[CompanyName],[Customers].[ContactName],[Customers].[Address],[Customers].[Phone] from [Customers] [Customers]
      where ([Customers].[Country] =:CountrySqlParameter)
      
    3. Switch to the Parameters tab and specify the following settings for the COUNTRYSQLPARAMETER parameter:

      1. Param type: ptInput
      2. Data type: ftString
      3. Data size: 15
      4. Value: Germany

      VCL Reports: FireDAC Query Editor — Configure a SQL Filter Parameter

    4. Click Execute to fetch corresponding records from the sample SQLite database:

      VCL Reports: FireDAC Query Editor — Execute the Resulting Query

    5. Close the FireDAC Query Editor dialog and enable the Active property in the Object Inspector.

    Data Source

    Select the TDataSource component and assign the configured TFDQuery component to the DataSet property using the Object Inspector.

    VCL Reports: Associate Datasource and FireDAC Query Components

    Bind the Report Viewer to Data

    Double-click the TdxBackendDataConnectionManager component on the form to open the Collection Editor dialog, click the Add button, and select the DataSet (JSON) option to create a TdxBackendDataSetJSONConnection component:

    VCL Reports: Create a Dataset Connection Component

    Select the created component and click the ellipsis button for the TdxBackendDataSetJSONConnection.DataSets property in the Object Inspector to display the Collection Editor dialog.

    VCL Reports: Display the "Collection Editor" Dialog for the Created Dataset Connection Component

    Click the Add New button to create a dataset link (TdxBackendDataSetCollectionItem) for the TdxBackendDataSetJSONConnection component:

    VCL Reports: Create a New Dataset Link Component

    Select the created TdxBackendDataSetCollectionItem component and use the Object Inspector to assign the previously configured TDataSource component to the TdxBackendDataSetCollectionItem.DataSource property:

    VCL Reports: Associate Dataset Link and Datasource Components

    Data is now accessible to the TdxReportControl component (according to the SQL query and filter parameter at the TFDQuery component level).

    Step 3 — Configure Data & Report Layout Using the Report Wizard

    Right-click the TdxReportControl component and select the Designer… option[1] to display the Report Designer dialog. Click the hamburger button to display the Report Designer menu.

    VCL Reports: The Report Designer Dialog

    Select Design in Report Wizard… to display available report types:

    VCL Reports: The Report Designer Menu

    Select Table Report on the Select Report Type page to create a tabular report and click Next.

    VCL Reports: Report Wizard — Select the "Table Report" Type

    Select JSON on the Select Data Source page to use the previously configured dataset connection component and click Next.

    VCL Reports: Report Wizard — Select the "JSON" Data Source

    The Select data fields pane displays all sample data fields selected at the dataset level using a SQL query. Click Next to navigate to the Define Report Layout step.

    VCL Reports: Report Wizard — Review Loaded Dataset Fields

    Select DataSource1 in panes 1 and 2, and click Finish.

    VCL Reports: Report Wizard — Select Queries and Fields

    Review and modify the generated report layout as necessary.

    VCL Reports: Report Designer — The Generated Table Report Layout

    Tip

    Refer to the following section for detailed information on report layout customization options:

    Reports for Web — Report Designer

    Save the report layout definition and close the Report Designer dialog.

    Data Loading Optimization

    To avoid redundant data reload/JSON serialization operations when an MDI Child form with a TdxReportControl component is displayed, do the following:

    1. Set the TdxReportControl.Active property to False.
    2. Select the TFDQuery component, expand the ActiveStoredUsage node in the Object Inspector, and uncheck the auRunTime option to ensure that the TFDQuery.Active property is disabled at application startup.

    VCL Reports: Data Loading Optimization Settings for FireDAC

    Tip

    At runtime, enable the TdxReportControl.Active property and open the TFDQuery dataset as demonstrated in the following section: Configure Bar Buttons.

    Step 4 — Add & Configure a Tabbed MDI UI

    MDI Form Configuration

    1. Switch to the main form, right-click a TdxBarManager component (dxBarManager1), and click Add Toolbar. Add two bar buttons (TdxBarButton) using the created toolbar’s context menu:

      VCL Reports: Add Toolbar Buttons on the Main Application Form

    2. Switch the main form’s FormStyle property from fsNormal to fsMDIForm using the Object Inspector.

    3. Select the TdxTabbedMDIManager component and set its Active property to True.

    4. Select the child form and switch its FormStyle property from fsNormal to fsMDIChild.

    Configure Bar Buttons

    Switch back to the main form, rename the first button to German Customers, double-click the button, and add the following OnClick event handler:

    procedure TMainForm.btnGermanCustomersClick(Sender: TObject);
    var
      AForm: TReportChildForm;
    begin
      AForm := TReportChildForm.Create(Self);  // dxReportControl1.Active is disabled at design time
      AForm.Caption := 'German Customers';
      // Apply the target filter criteria to data using the previously configured report parameter
      AForm.FDQuery1.ParamByName('CountrySqlParameter').Value := 'Germany';
      AForm.FDQuery1.Open;                     // Fetches data according to the specified filter criteria
      AForm.dxReportControl1.Active := True;   // Displays report content
    end;
    

    Rename the second button to UK Customers, double-click the button, and add the following OnClick event handler:

    procedure TMainForm.btnUKCustomersClick(Sender: TObject);
    var
      AForm: TReportChildForm;
    begin
      AForm := TReportChildForm.Create(Self);  // dxReportControl1.Active is disabled at design time
      AForm.Caption := 'UK Customers';
      // Apply the target filter criteria to data using the previously configured report parameter
      AForm.FDQuery1.ParamByName('CountrySqlParameter').Value := 'UK';
      AForm.FDQuery1.Open;                    // Fetches data according to the specified filter criteria
      AForm.dxReportControl1.Active := True;  // Displays report content
    end;
    

    Step 5 — Build & Test Your App

    Post-Build Events for WebView2 Loader DLL Deployment

    All applications that include the TdxReportControl component require the WebView2 Runtime as a dependency.

    To automatically copy a 32- or 64-bit WebView2Loader.dll file to the target build folder, do the following:

    1. Open the Project Options dialog. Select the ProjectOptions… item in the RAD Studio menu or press Ctrl + Shift + F11).
    2. Select BuildBuild Events in the tree view pane on the left and select the following option in the Target combo box:

      'All Configurations - All Platforms'

      VCL Shared Libraries: Project Options — Select the Target Platform

    3. Copy the command line for the target compiler and platform:

      copy /Y "$(BDS)\Redist\$(Platform)\WebView2Loader.dll" "$(OUTPUTDIR)"
      
    4. Paste the DLL deployment command line into the Commands box:

      VCL Shared Libraries: Paste the DLL Deployment Command Line

    5. Optional. This step is required only for the Modern C++ RAD Studio compiler.

      If you use Windows 64-bit (Modern) as a build target, select the Windows 64-bit (Modern) platform (1), expand the Post-build eventsCommands node (2), uncheck the Inherit option (3), and paste the Modern compiler-specific command into the Commands box (4):

      VCL Shared Libraries: Project Options — Paste Windows 64-bit Modern-Specific Command Line

    6. Click Save to apply pending changes and close the Project Options dialog.

    7. Build the project. Confirm that the configured post-build event is trusted in the following dialog:

      VCL Reports: The "Trust this Project" Dialog

    All build operations in the current RAD Studio project now ensure that the platform-specific WebView2Loader.dll file version is available in the target build folder (for both Debug and Release configurations).

    Run & Test the App

    Run the app and click bar buttons to create corresponding tabbed child MDI forms. Click tabs to switch between different data within the same report layout displayed using a TdxReportControl component.

    VCL Reports: A DevExpress Report Control-Powered Multi-Document Interface App

    Other Tutorials

    Read Tutorial: Bind a Report to a Stored Procedure
    Follow this tutorial to create a table report, bind it to a stored database procedure, and pass a report parameter to that procedure using Report Designer and Report Wizard dialogs at design time.
    Read Tutorial: Create a Master-Detail Report with a Detail Band
    Follow this tutorial to create a master-detail relationship between two tables in a relational SQL database and display hierarchical data in a table report.
    Read Tutorial: Embed a Parametrized Report into a Form
    Follow this tutorial to create a Tabbed MDI (multi-document interface) Report Viewer application where different tabs allow users to display different data from a relational SQL database in the same report template.
    Footnotes
    1. Alternatively, you can double-click the TdxReportControl component.

    See Also