TdxReportCustomInMemoryJSONConnection.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 TdxReportInMemoryJSONConnection and TdxReportDataSetJSONConnection components (TdxReportCustomInMemoryJSONConnection descendants).
In-Memory JSON Connection Component
ConnectionString
is the main property[1] in the TdxReportInMemoryJSONConnection class. You can use this property to:
- Specify required data as a JSON string (as demonstrated in the code example below).
Specify a Web Service Endpoint URL or a path to the required JSON file. For example:
'Uri=https://northwind.netcore.io/customers.json;Username=user; Password=pwd; header:MyAuthHedaer1=secretToken1; header:MyAuthHeader2=secretToken2; query:id=123456;query=name=MyName'
Tip
Refer to the following topic for detailed information in this regard: JSON Data.
Dataset-Based JSON Connection Component
The ConnectionString
property stores serialized JSON data from datasets associated with a TdxReportDataSetJSONConnection component. Use the DataSets property to bind and configure one or multiple datasets (TdxMemData, TFDTable, TFDQuery, etc.).
Code Example: Generate Reports Based on In-Memory Data
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
dxReport.ConnectionString.JSON; // Declares the TdxReportInMemoryJSONConnection component
// ...
procedure TMyForm.Button1Click(Sender: TObject);
var
AJSONDataConnection: TdxReportInMemoryJSONConnection;
AReport: TdxReport;
AFileStream: TFileStream;
begin
AJSONDataConnection := TdxReportInMemoryJSONConnection.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;
Default Value
The ConnectionString
property’s default value is an empty string.
-
Available in the Object Inspector.