TdxReport.EnableCustomSql Property
Specifies if custom SQL queries are enabled at the component level.
Declaration
property EnableCustomSql: TdxDefaultBoolean read; write; default bDefault;
Property Value
| Type | Default | Description |
|---|---|---|
| TdxDefaultBoolean | bDefault | Specifies if the current TdxReport component executes a custom SQL query created within the current layout definition and allows users to input custom SQL queries in the UI:
|
Remarks
A layout definition loaded using the Layout property may include a SQL query if the TdxReport component connects to a relational database system using the TdxBackendDatabaseSQLConnection component.
Important
Custom SQL queries specified within the report layout definition are initially disabled and custom SQL query-related functionality is disabled in the UI.
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.
You can set the EnableCustomSql property to bTrue or bFalse to explicitly enable or disable custom SQL queries and corresponding UI elements for the current TdxReport component.
Code Examples
Enable Custom SQL Queries at the Component Level
The following code example configures a TdxBackendDatabaseSQLConnection component and enables custom SQL queries at the TdxReport component level:
uses
dxReport, // Declares the TdxReport component
dxBackend.ConnectionString.SQL; // Declares the TdxBackendDatabaseSQLConnection component
// ...
procedure TMyForm.cxDisplayDesignerButtonClick(Sender: TObject);
begin
dxReport1.EnableCustomSql := bTrue; // Enables custom SQL queries at the component level
dxBackendDatabaseSQLConnection1.Active := False; // Terminates the current connection (if one exists)
// Specify a user-friendly data connection name (for end-user dialogs) and a valid connection string:
dxBackendDatabaseSQLConnection1.DisplayName := 'PostgreSQL Database Connection';
dxBackendDatabaseSQLConnection1.ConnectionString :=
'XpoProvider=Postgres;' + // Specifies the database engine type
'Server=127.0.0.1;' + // Specifies the database host IP address
'User ID=myuser;' + // Specifies a valid user name
'Password=123;' + // Specifies the corresponding password for the user name
'Database=dashboard_test;' + // Specifies the target database name
'Encoding=UNICODE'; // Sets UTF-8 as the required encoding
dxBackendDatabaseSQLConnection1.Active := True; // Connects to the test database
dxReport1.ShowDesigner; // Displays the Report Designer dialog
end;
Enable Custom SQL Queries at Startup
The code example demonstrated in this section changes the TdxBackendDatabaseSQLConnection.DefaultEnableCustomSql class property value to True in the initialization section of the main application unit for all TdxDashboard/TdxDashboardControl and TdxReport components in the project.
To open the main application unit of your project, you can use one of the following options:
- Select Project → View Source in the main menu of your RAD Studio IDE.
- Select the target project in the Projects Window and press Ctrl + V (alternatively, you can display the context menu and select the View Source option).
uses
Forms,
dxBackend.ConnectionString.SQL; // Declares the TdxBackendDatabaseSQLConnection component
// ...
begin
TdxBackendDatabaseSQLConnection.DefaultEnableCustomSql := True; // Enables custom SQL queries globally
Application.Initialize;
Application.MainFormOnTaskBar := True;
Application.CreateForm(TMyForm, MyForm);
Application.Run;
end.
Default Value
The EnableCustomSql property’s default value is bDefault.
The default EnableCustomSql property value indicates that the TdxBackendDatabaseSQLConnection.DefaultEnableCustomSql property determines if custom SQL queries are enabled.