vcl-dxreport-dot-tdxreport-5dfd7a63.md
Specifies the report name.
property ReportName: string read; write;
| Type | Description |
|---|---|
| string |
The report name.
|
Use the ReportName property to define a report name for export operations when the Layout property contains a non-empty report template. Report Viewer and Report Designer dialogs also display the ReportName property value in the form caption.
The GetExportResultFileName function returns the full exported file name composed of the ReportName property value and the file name extension that corresponds to the current export format.
To save the current report template state during the current session, users can click the hamburger button in the Report Designer dialog and select the Save option. If the TdxReport.ReportName property value is an empty string, the Report Designer dialog prompts a user to specify a report name:
The report is saved in memory. You can access the report using the Layout property.
The following code example saves the current report to a REPX file every time a user saves pending changes in the Report Designer dialog:
uses
dxReport; // Declares the TdxReport class
// ...
procedure TMyForm.dxReport1LayoutChanged(ASender: TdxReport);
begin
ASender.Layout.SaveToFile(ASender.ReportName + '.repx');
end;
#include "dxReport.hpp" // Declares the TdxReport class
// Add the following linker directive to the corresponding CPP source file:
#pragma link "dxReport" // Required to use dxReport.hpp declarations
// ..
void __fastcall TMyForm::dxReport1LayoutChanged(TdxReport *ASender)
{
ASender->Layout->SaveToFile(ASender->ReportName + ".repx");
}
The following code example saves the current report to an existing BLOB dataset field every time a user saves pending changes in the Report Designer dialog:
uses
dxReport, // Declares the TdxReport class
dxmdaset; // Declares the TdxMemData class and related types
// ...
procedure TMyForm.dxReport1LayoutChanged(ASender: TdxReport);
begin
dxMemData1.Edit;
dxMemData1.FieldByName('TemplateName').AsString := ASender.ReportName;
dxMemData1.FieldByName('TemplateLayout').Assign(ASender.Layout);
dxMemData1.Post;
end;
#include "dxReport.hpp" // Declares the TdxReport class
#include "dxmdaset.hpp" // Declares the TdxMemData class and related types
// Add the following linker directives to the corresponding CPP source file:
#pragma link "dxReport" // Required to use dxReport.hpp declarations
#pragma link "dxmdaset" // Required to use dxmdaset.hpp declarations
// ...
void __fastcall TMyForm::dxReport1LayoutChanged(TdxReport *ASender)
{
dxMemData1->Edit();
dxMemData1->FieldByName("TemplateName")->AsString = ASender->ReportName;
dxMemData1->FieldByName("TemplateLayout")->Assign(ASender->Layout);
dxMemData1->Post();
}
The following code example loads an XML-based report template (TdxReport.Layout) from a REPX file, populates the template with test data defined in a connection string, and exports the resulting report as a PNG image:
uses
dxReport, // Declares the TdxReport component and related types
dxBackend.ConnectionString.JSON; // Declares the TdxBackendInMemoryJSONConnection component
// ...
procedure TMyForm.Button1Click(Sender: TObject);
var
AJSONDataConnection: TdxBackendInMemoryJSONConnection;
AReport: TdxReport;
AFileStream: TFileStream;
begin
AJSONDataConnection := TdxBackendInMemoryJSONConnection.Create(Self);
try
AJSONDataConnection.Name := 'JSONData';
// Specify in-memory report data as a connection string
AJSONDataConnection.ConnectionString :=
'Json=''[{"id":1, "caption":"test1"},{"id":2, "caption":"test2"}]''';
AReport := TdxReport.Create(Self);
try
AReport.ReportName := 'Report';
AReport.Layout.LoadFromFile('Report.repx'); // Loads a report template
AFileStream := TFileStream.Create('Report.png', fmOpenReadWrite);
try
AReport.ExportToImage(AFileStream); // Exports the report in the default image export format (PNG)
finally
AFileStream.Free;
end;
finally
AReport.Free;
end;
finally
AJSONDataConnection.Free;
end;
end;
#include "dxReport.hpp" // Declares the TdxReport component
#include "dxBackend.ConnectionString.JSON.hpp" // Declares the TdxBackendInMemoryJSONConnection component
// Add the following linker directives to the corresponding CPP source file:
#pragma link "dxReport" // Required for dxReport.hpp declarations
#if defined(_WIN64) // Required to use dxBackend.ConnectionString.JSON.hpp declarations
#pragma link "dxBackend.ConnectionString.JSON.o"
#else
#pragma link "dxBackend.ConnectionString.JSON.obj"
// ...
void __fastcall TMyForm::Button1Click(TObject *Sender)
{
TdxBackendInMemoryJSONConnection *AJSONDataConnection;
TdxReport *AReport;
TFileStream *AFileStream;
AJSONDataConnection = new TdxBackendInMemoryJSONConnection(this);
try
{
AJSONDataConnection->Name = "JSONData";
// Specify in-memory report data as a connection string
AJSONDataConnection->ConnectionString =
"Json=\"\"[{\"id\":1, \"caption\":\"test1\"}, {\"id\":2, \"caption\":\"test2\"}]\"";
AReport = new TdxReport(this);
try
{
AReport->ReportName = "Report";
AReport->Layout->LoadFromFile("Report.repx"); // Loads a report template
AFileStream = new TFileStream('Report.png', fmOpenReadWrite);
try
{
AReport->ExportToImage(AFileStream); // Exports the report in the default image export format (PNG)
}
__finally
{
delete AFileStream;
}
}
__finally
{
delete AReport;
}
}
__finally
{
delete AJSONDataConnection;
}
}
View Example: Store report layouts within text filesView Example: Store report layouts in a database
The ReportName property’s default value is an empty string.
The default ReportName property value indicates that the ShowDesigner procedure displays an empty template in the Report Designer dialog, even if the Layout property contains a non-empty template. Any subsequent saved changes made in the Report Designer dialog override both ReportName and Layout property values.
See Also