Skip to main content
All docs
V25.2
  • Bind a Report to a Database/SQL View Using Standard FireDAC and DataSet Components

    • 4 minutes to read

    This tutorial creates a new project, sets up FireDAC components shipped with the RAD Studio IDE, adds a TdxReport component, and uses the Report Wizard to set up a table report at design time.

    VCL Reports: Generated Report Preview Example

    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\devav.sqlite3

    Download: Compiled VCL Demos

    Step 1 — Create & Configure a RAD Studio Project

    Create a new Delphi or C++Builder project.

    Place Components on a Form

    DevExpress Components

    TdxBackendDataConnectionManager
    Manages data sources for all reports in your application.
    TdxReport
    Manages report document layouts, end-user dialogs, and related settings.

    FireDAC Components

    TFDConnection
    A standard component designed to establish a connection to a database management system.
    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: A Form with Required Components

    Configure FireDAC Components

    FireDAC Connection

    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 (devav.sqlite3) 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

    1. Double-click the TFDQuery component to display the FireDAC Query Editor dialog.
    2. Paste the following SQL query into the command editor:

      SELECT * FROM CUSTOMERS
      
    3. Click Execute to fetch corresponding records from the sample SQLite database:

      VCL Reports: The FireDAC Query Editor

    4. 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 Generator 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

    The sample SQLite database is now accessible to the TdxReport component.

    Step 2 — Design a Report Layout Using the Report Wizard

    Right-click the TdxReport component and select the Designer option to display the Report Designer dialog. Click the hamburger menu in the bottom-left corner to display the Report Designer menu and select Design in the 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 layout and click Next.

    VCL Reports: Report Wizard — Available Report Types

    Select JSON on the Select Data Source page to use the previously configured connection component as a data source and click Next.

    VCL Reports: Report Wizard — Select Data Source

    The Specify Data Source Settings page displays the configured data source. Review the list of loaded dataset fields in the Select data fields pane and click Next.

    VCL Reports: Report Wizard — Review Loaded Dataset Fields

    Check DataSource1 in pane 1, check all required dataset fields in pane 2, and click Finish to create a table report layout with all selected fields.

    VCL Reports: Report Wizard — Select Required Dataset Fields

    The Report Designer dialog displays the generated report template:

    VCL Reports: Report Designer — The Generated Report Template

    Next Steps (3, 4, and 5)

    To preview/modify the created report template, display Report Designer/Report Viewer dialogs at runtime, and deploy the resulting application, follow steps 3, 4, and 5 of the basic Report Generation Tutorial:

    Step 3 — Modify/Preview & Save the Generated Report Layout

    This tutorial step contains basic information on report edit and preview functionality.

    Tip

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

    Report for Web — Report Designer

    Step 4 — Display Report Viewer & Designer Dialogs at Runtime
    TdxReport is a non-visual component. Follow this tutorial step to display end-user dialogs at runtime using ShowDesigner and ShowViewer methods.
    Step 5 — Build & Test Your First App
    This step explains how to use post-build events in the RAD Studio IDE for automatic dependency deployment for the TdxReport component.
    See Also