Skip to main content
All docs
V26.1
  • TdxReport.ReportName Property

    Specifies the report name.

    Declaration

    property ReportName: string read; write;

    Property Value

    Type Description
    string

    The report name.

    Remarks

    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.

    End-User Functionality

    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:

    VCL Reports: The Report Name Dialog

    The report is saved in memory. You can access the report using the Layout property.

    Code Examples

    Save Report Layout Changes to File on Every Change

    The following code example saves the current Report layout to a file in the REPX format 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 + '.xml');
    end;
    

    Save Report Layout to Database on Every Change

    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;
    

    Generate and Export Report Content to PDF File

    The following code example configures a memory-based data source (TdxBackendInMemoryJSONConnection), loads an XML layout, and exports generated content to a file in the Portable Document (PDF) format without user interaction:

    uses
      dxBackend.ConnectionString.JSON,  // Declares the TdxBackendInMemoryJSONConnection component
      dxReport;                      // Declares the TdxReport class
    // ...
    
    procedure TMyForm.cxButtonExportToPDFClick(Sender: TObject);
    var
      AReport: TdxReport;
      AJSONDataConnection: TdxBackendInMemoryJSONConnection;
      AMemoryStream: TMemoryStream;
      AJSONData: string;
    begin
      // Define a table that consists of three columns ("id", "Region", and "Sales") and five data rows:
      AJSONData :=
    
      '[{"id": 1, "Region": "Asia",          "Sales": 4.7685},' +  // Row #1
       '{"id": 2, "Region": "Australia",     "Sales": 1.9576},' +  // Row #2
       '{"id": 3, "Region": "Europe",        "Sales": 3.3579},' +  // Row #3
       '{"id": 4, "Region": "North America", "Sales": 3.7477},' +  // Row #4
       '{"id": 5, "Region": "South America", "Sales": 1.8237}]';   // Row #5
    
      AJSONDataConnection := TdxBackendInMemoryJSONConnection.Create(Self);  // Creates a data connection
      try
        AJSONDataConnection.Name := 'JSONData';        // Assigns a name to the created data connection
        AJSONDataConnection.SetJSONValue(AJSONData);   // Assigns the defined JSON data string
        AReport := TdxReport.Create(Self);       // Creates a TdxReport container
        try
          AReport.Layout.LoadFromFile('MyReportLayout.xml');  // Loads an XML Report layout
          AReport.ReportName := 'MyReport';                         // Defines a Report name
          AMemoryStream := TMemoryStream.Create;                    // Creates a memory stream
          try
            // Export Report content to the created memory stream in the PDF format:
            AReport.ExportToPDF(AMemoryStream);
            AMemoryStream.SaveToFile(AReport.ReportName + '.pdf');   // Saves the resulting PDF file
          finally
            AMemoryStream.Free;         // Releases the memory stream
          end;
        finally
          AReport.Free;              // Releases the TdxReport container
        end;
      finally
        AJSONDataConnection.Free;       // Releases the data connection
      end;
    end;
    

    View Example: Store report layouts within text files View Example: Store report layouts in a database

    Default Value

    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