Back to Devexpress

TdxBackendCustomInMemoryJSONConnection.SetJSONValue(string) Method

vcl-dxbackend-dot-connectionstring-dot-json-dot-tdxbackendcustominmemoryjsonconnection-dot-setjsonvalue-x28-system-dot-string-x29.md

latest4.1 KB
Original Source

TdxBackendCustomInMemoryJSONConnection.SetJSONValue(string) Method

Sets component data to the specified JSON value.

Declaration

delphi
procedure SetJSONValue(const AJSONValue: string);

Parameters

NameTypeDescription
AJSONValuestring

The specified JSON value.

|

Remarks

Call the SetJSONValue procedure and pass the required JSON data string to replace existing content stored in the component.

Code Example: Assign a JSON Data String

The following code example demonstrates an OnClick event handler that calls the SetJSONValue procedure to assign a table defined within a JSON string to the TdxBackendInMemoryJSONConnection component and displays the Dashboard Designer dialog:

delphi
uses
  dxDashboard.Control, // Declares the TdxDashboardControl component
  dxBackend.ConnectionString.JSON; // Declares the TdxBackendInMemoryJSONConnection component
// ...

procedure TMyForm.cxDisplayDesignerButtonClick(Sender: TObject);
var
  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

  // Specify a user-friendly data connection name (for end-user dialogs):
  dxBackendInMemoryJSONConnection1.DisplayName := 'Memory-Based JSON Data Storage';
  dxBackendInMemoryJSONConnection1.SetJSONValue(AJSONData); // Assigns the defined JSON data string
  dxDashboardControl1.ShowDesigner; // Displays the Dashboard Designer dialog
end;
cpp
#include "dxDashboard.Control.hpp" // Declares the TdxDashboardControl component
#include "dxBackend.ConnectionString.JSON.hpp" // Declares the TdxBackendInMemoryJSONConnection component

// Add the following linker directives to the corresponding CPP source file:
#pragma link "dxDashboard.Control" // Required to use dxDashboard.Control.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"
#endif
// ...

void __fastcall TMyForm::cxDisplayDesignerButtonClick(TObject *Sender)
{
  // Define a table that consists of three columns ("id", "Region", and "Sales") and five data rows:
  UnicodeString AJSONData =

    L"[{\"id\": 1, \"Region\": \"Asia\", \"Sales\": 1.9576}," // Row #1
     L"{\"id\": 2, \"Region\": \"Australia\", \"Sales\": 1.9576}," // Row #2
     L"{\"id\": 3, \"Region\": \"Europe\", \"Sales\": 3.3579}," // Row #3
     L"{\"id\": 4, \"Region\": \"North America\", \"Sales\": 3.7477}," // Row #4
     L"{\"id\": 5, \"Region\": \"South America\", \"Sales\": 1.8237}]" // Row #5

  // Specify a user-friendly data connection name (for end-user dialogs):
  dxBackendInMemoryJSONConnection1->DisplayName = "Memory-Based JSON Data Source";
  dxBackendInMemoryJSONConnection1->SetJSONValue(AJSONData); // Assigns the defined JSON data string
  dxDashboardControl1->ShowDesigner(); // Displays the "Dashboard Designer" dialog
}

See Also

TdxBackendCustomInMemoryJSONConnection.ConnectionString Property

TdxBackendCustomInMemoryJSONConnection Class

TdxBackendCustomInMemoryJSONConnection Members

dxBackend.ConnectionString.JSON Unit