Back to Devexpress

TdxReport Class

vcl-dxreport.md

latest16.8 KB
Original Source

TdxReport Class

An AI-powered Report Generator component.

Declaration

delphi
TdxReport = class(
    TcxCustomComponent
)

Remarks

TdxReport is a non-visual component designed to generate customizable reports based on templates populated with placeholder fields. The report generator implementation is based on the DevExpress Javascript Report Designer and Viewer adapted for use in native VCL apps (using modern web-based design capabilities based on WebView and ASP.NET Core).

All required .NET and JS dependencies are embedded into one self-contained EXE file transparently.

Prerequisites & Deployment

Note

Ensure that your development environment meets ExpressDashboards and ExpressReports prerequisites:

  1. Microsoft Windows 10 or newer.
  2. Embarcadero RAD Studio IDE 12.3 or newer (Community Edition IDEs are not supported).
  3. DevExpress VCL v25.2.x.
  4. The EdgeView2 SDK package installed from the GetIt package manager.

Tip

Refer to the following topic for detailed information: VCL Reports/Dashboards App Deployment.

Bind to Data

TdxReport can populate placeholder fields in a template from different data sources stored in memory or a database. The TdxBackendDataConnectionManager component allows you to manage data connection components designed to work with different data sources.

Tip

You can create data connection components directly in code, without TdxBackendDataConnectionManager.

Refer to the data connection class descriptions for detailed information and code examples.

Data Connection Components

TdxBackendDataSetJSONConnection

A component designed to work with data in one or multiple VCL-compatible datasets (TDataSet descendants).

Use the TdxBackendDataSetJSONConnection component if you need to use TdxDashboardControl/TdxDashboard and TdxReport components together with VCL-compatible data sources.

Refer to the following help topic for step-by-step instructions on using the TdxBackendDataSetJSONConnection component in your project:

VCL Reports/Dashboards: How to Use Data Source and Data Set Components

TdxBackendInMemoryJSONConnection

A component designed for interaction with local (in-memory) or remote JSON data accessible through a Web API service endpoint.

Refer to the following help topic for step-by-step instructions on using the TdxBackendInMemoryJSONConnection component as a data source for TdxDashboard/TdxDashboardControl and TdxReport:

VCL Reports/Dashboards: How to Use Memory-Based or Remote API Data Sources

TdxBackendDatabaseSQLConnection

A DevExpress XPO-based component designed to fetch data from the following relational databases:

SQLite | Microsoft SQL Server/Azure SQL | PostgreSQL | Oracle Database | MySQL | Firebird

Tip

This component is based on the DevExpress XPO ORM engine (powered by ADO.NET).

TdxBackendDatabaseSQLConnection has built-in support for Microsoft SQL/Azure SQL and SQLite engines (you can use them without additional dependencies and extra configuration).

Refer to the following topic for a complete list of supported database engines and corresponding connection string examples:

VCL Reports/Dashboards: Supported Database Engines

Main API Members

The list below outlines key members of the TdxReport class. These members allow you to configure templates, generate reports, and export report content in different target formats.

Report Content and Layout

ClearClears the current report name, layout, and parameters.EnableCustomSql

Specifies if custom SQL queries are enabled at the TdxReport component level.

Important

Enable custom SQL queries only if you ensure that you follow best practices and implement user read/write privileges at the database level using the tools available for your relational database management system.

FilterStringSpecifies filter criteria for report data.GroupNameAllows you to group multiple TdxReport components. All components within the same group use shared VCL backend resources.LanguageAllows you to switch between available UI and report template localizations. Refer to the following topic for information on localization techniques: VCL Reports Localization.LayoutProvides access to the report REPX template (as individual XML strings).OnLayoutChangedAllows you to respond to any report layout changes.Parameters

Provides access to the read-only collection of report parameters.

Note

The Parameters collection is automatically populated and updated from the current report template definition.

ReportNameSpecifies the report name.

End-User Interaction

ExportFormatsSpecifies export formats available to users in the Report Preview dialog.OnExportAllows you to execute custom code in response to preview file download operations or to prevent users from downloading previews.OnDesignerFormShow | OnViewerFormShowAllow you to customize Report Designer and Report Viewer dialog form settings (position, dimensions, caption, etc.).OnPrintPreviewAllows you to respond to print preview operations and obtain preview content as a PDF document.ShowDesigner | ShowViewer

Display Web-based Report Designer and Report Preview dialogs. Global skin and palette settings (defined using the Project Settings dialog or a TdxSkinController component) affect these dialogs.

Tip

You can click the Designer… or Viewer… item in the TdxReport component’s context menu to display the corresponding dialog at design time.

Data Export

ExportToExports the current report to a stream in any supported format.ExportToCSV | ExportToDOCX | ExportToHTML | ExportToMHT | ExportToPDF | ExportToRTF | ExportToRTF | ExportToText | ExportToXLS | ExportToXLSXExport the current report to a stream in corresponding formats.ExportToImage

Exports the current report to a stream as an image (PNG is the default image export format).

Tip

The current image format is defined in Export Options available in the Web-based Report Preview dialog.

GetExportResultFileNameReturns the full report file name for export operations.

Code Examples

Related GitHub-Hosted Example Projects

View Example: Store Report Layouts within Text FilesView Example: Store Report Layouts in a DatabaseView Example: Localize the DevExpress Report Viewer and Report Designer

Connect to a SQL Database and Edit Report Templates

The following code example uses the TdxBackendDatabaseSQLConnection component to connect to a demo database (devav.sqlite3), displays the Report Designer dialog, and saves all changes made to the UserReport.repx file:

delphi
uses
  dxReport, // Declares the TdxReport component and related types
  dxBackend.ConnectionString.SQL; // Declares the TdxBackendDatabaseSQLConnection component
// ...

procedure TMyForm.Button1Click(Sender: TObject);
var
  ADataConnection: TdxBackendDatabaseSQLConnection;
  AReport: TdxReport;
begin
  ADataConnection := TdxBackendDatabaseSQLConnection.Create(Self); // Creates a database connection
  try
    ADataConnection.Name := 'SQLite Database Connection';
    // Specify a connection string required to connect to a demo database (devav.sqlite3)
    ADataConnection.ConnectionString := 'XpoProvider=SQLite;' + // Specifies the database engine type
      'Data Source=C:\Users\Public\Documents\DevExpress VCL Demos\MegaDemos\' +
      'Product Demos\ExpressReports\Data\devav.sqlite3';
    AReport := TdxReport.Create(Self); // Creates a TdxReport component
    try
      AReport.ShowDesigner; // Displays the Report Designer dialog
      AReport.Layout.SaveToFile('UserReport.repx'); // Saves the report template state to a file
    finally
      AReport.Free; // Releases the created TdxReport component
    end;
  finally
    ADataConnection.Free; // Releases the database connection component
  end;
end;
cpp
#include "dxReport.hpp" // Declares the TdxReport component and related types
#include "dxBackend.ConnectionString.SQL.hpp" // Declares the TdxBackendDatabaseSQLConnection component

// Add the following linker directives to the corresponding CPP source file:
#pragma link "dxReport" // Required to use dxReport.hpp declarations
#if defined(_WIN64) // Required to use dxBackend.ConnectionString.SQL.hpp declarations
  #pragma link "dxBackend.ConnectionString.SQL.o"
#else
  #pragma link "dxBackend.ConnectionString.SQL.obj"
// ...

void __fastcall TMyForm::Button1Click(TObject *Sender)
{
  TdxBackendDatabaseSQLConnection *ADataConnection;
  TdxReport *AReport;
  ADataConnection = new TdxBackendDatabaseSQLConnection(this); // Creates a database connection
  try
  {
    ADataConnection->Name = "SQLite Database Connection";
    // Specify a connection string required to connect to a demo database (devav.sqlite3)
    ADataConnection->ConnectionString = "XpoProvider=SQLite;" // Specifies the database engine type
      "Data Source=C:\\Users\\Public\\Documents\\DevExpress VCL Demos\\MegaDemos\\"
      "Product Demos\\ExpressReports\\Data\\devav.sqlite3";
    AReport = new TdxReport(this); // Creates a TdxReport component
    try
    {
      AReport->ShowDesigner(); // Displays the Report Designer dialog
      AReport->Layout->SaveToFile("UserReport.repx"); // Saves the report template state to a file
    }
    __finally
    {
      delete AReport; // Releases the created TdxReport component
    }
  }
  __finally
  {
    delete ADataConnection; // Releases the database connection component
  }
}

To see the TdxReport component in action, run the Report Designer/Viewer demo in the VCL Demo Center installed with compiled DevExpress VCL demos. Click different items in the sidebar on the left to switch between demo features.

Download: Compiled VCL Demos

Tip

You can find full source code for the installed compiled Report demo in the following folder:

_%PUBLIC%\Documents\DevExpress VCL Demos\MegaDemos\Product Demos\ExpressReports_

Inheritance

TObject TPersistent TComponent TcxCustomComponent TdxReport

See Also

TdxDashboardControl Class

TdxDashboard Class

Backend for VCL Reports/Dashboards

TdxReport Members

dxReport Unit