Skip to main content
All docs
V26.1
  • TdxBackendCustomInMemoryJSONConnection.ConnectionString Property

    Specifies a connection string or stores serialized data (in the JSON format).

    Declaration

    property ConnectionString: string read; write;

    Property Value

    Type Description
    string

    The connection string or serialized data in the JSON format.

    Remarks

    The ConnectionString property serves different purposes for TdxBackendInMemoryJSONConnection and TdxBackendDataSetJSONConnection components (TdxBackendCustomInMemoryJSONConnection descendants).

    Component-Specific Property Behavior

    In-Memory JSON Connection Component

    ConnectionString is the main property[1] in the TdxBackendInMemoryJSONConnection class. You can use this property to:

    • Specify required data as a JSON string.
    • Specify a Web Service Endpoint URL or a path to the required JSON file.

    Dataset-Based JSON Connection Component

    The ConnectionString property stores serialized JSON data from datasets associated with the TdxBackendDataSetJSONConnection component. Use the DataSets property to bind and configure one or multiple datasets (TdxMemData, TFDTable, TFDQuery, etc.).

    Code Examples

    Assign JSON Data as a Connection String

    The following code example demonstrates an OnClick event handler that configures a TdxBackendInMemoryJSONConnection component, assigns a table defined within a JSON string to the ConnectionString property, and displays the Dashboard Designer dialog:

    uses
      dxDashboard.Control,              // Declares the TdxDashboardControl component
      dxBackend.ConnectionString.JSON;  // Declares the TdxBackendInMemoryJSONConnection component
    // ...
    
    procedure TMyForm.cxDisplayDesignerButtonClick(Sender: TObject);
    begin
      // Specify a user-friendly data connection name (for end-user dialogs):
      dxBackendInMemoryJSONConnection1.DisplayName := 'Memory-Based JSON Data Source';
      // Define a table that consists of three columns ("id", "Region", and "Sales") and five data rows:
      dxBackendInMemoryJSONConnection1.ConnectionString := 'Json=''' +
    
        '[{"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
    
      dxDashboardControl1.ShowDesigner;  // Displays the "Dashboard Designer" dialog
    end;
    

    Load JSON Data from a Remote Source

    The code example in this section demonstrates an OnClick event handler that configures a TdxBackendInMemoryJSONConnection component used to load JSON data from an external source using a connection string and displays the Dashboard Designer dialog.

    Note

    This code example demonstrates a sample connection string. You must replace specified parameter values with required URI, username, password, access tokens, etc.

    uses
      dxDashboard.Control,              // Declares the TdxDashboardControl component
      dxBackend.ConnectionString.JSON;  // Declares the TdxBackendInMemoryJSONConnection component
    // ...
    
    procedure TMyForm::cxDisplayDesignerButtonClick(Sender: TObject);
    begin
      dxBackendInMemoryJSONConnection1.Active := False;  // Terminates the current connection (if one exists)
      // Specify a user-friendly data connection name (for end-user dialogs):
      dxBackendInMemoryJSONConnection1.DisplayName := 'Memory-Based JSON Data Source';
      dxBackendInMemoryJSONConnection1.ConnectionString :=
    
        'Uri=https://northwind.netcore.io/customers.json;' + // Specifies the path to a source JSON file
        'Username=user;' +                      // Specifies a valid user name
        'Password=pwd;' +                       // Specifies the corresponding password for the user name
        'MyAuthHeader1=secretToken1;MyAuthHeader2=secretToken2;' +  // Specifies authentication tokens
        'query:id=123456;query:name=MyName;'    // Specifies the required query ID and name
    
      dxBackendInMemoryJSONConnection1.Active := True;   // Connects to the target Web service endpoint
      dxDashboardControl1.ShowDesigner();                // Displays the "Dashboard Designer" dialog
    end;
    

    Load Data from a DevExpress JSON Sample

    The following code example uses a sample JSON file hosted on GitHub by DevExpress as a data source for the TdxBackendInMemoryJSONConnection component:

    uses
      dxDashboard.Control,              // Declares the TdxDashboardControl component
      dxBackend.ConnectionString.JSON;  // Declares the TdxBackendInMemoryJSONConnection component
    // ...
    
    procedure TMyForm.cxDisplayDesignerButtonClick(Sender: TObject);
    var
      AUri: string;
    begin
      AUri := 'Uri=https://raw.githubusercontent.com/DevExpress-Examples/DataSources/master/JSON/customers.json';
      // Specify a user-friendly data connection name (for end-user dialogs):
      dxBackendInMemoryJSONConnection1.DisplayName := 'Memory-Based JSON Data Storage';
      dxBackendInMemoryJSONConnection1.ConnectionString := AUri;  // Assigns the target Web Service URI
      dxDashboardControl1.ShowDesigner;                           // Displays the "Dashboard Designer" dialog
    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
      dxSplashForms,                    // Declares the TdxSplashFormManager class and related types
      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
          TdxSplashFormManager.WaitForm.Show(Self);    // Displays a Wait Form before the export operation
          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
            TdxSplashFormManager.WaitForm.Hide;        // Hides the Wait Form once the operation is complete
          end;
        finally
          AReport.Free;              // Releases the TdxReport container
        end;
      finally
        AJSONDataConnection.Free;       // Releases the data connection
      end;
    end;
    

    Default Value

    The ConnectionString property’s default value is an empty string.

    Footnotes
    1. Available in the Object Inspector.

    See Also