Skip to content

Commit 86dbe29

Browse files
committed
readme: draft
1 parent eb23b42 commit 86dbe29

8 files changed

Lines changed: 154 additions & 16 deletions

Delphi/uData.dfm

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ object DataModule1: TDataModule1
55
Width = 740
66
PixelsPerInch = 192
77
object mdLayouts: TdxMemData
8-
Active = True
98
Indexes = <>
109
Persistent.Data = {
1110
5665728FC2F5285C8FFE3F02000000000000000D0007004C61796F7574001400
@@ -795,7 +794,7 @@ object DataModule1: TDataModule1
795794
0072007400}
796795
SortOptions = []
797796
Left = 408
798-
Top = 112
797+
Top = 104
799798
object mdLayoutsLayout: TBlobField
800799
FieldName = 'Layout'
801800
end

Delphi/uMainForm.pas

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,13 @@ procedure TMainForm.btnPreviewClick(Sender: TObject);
7979
dxReport1.ShowViewer;
8080
end;
8181

82+
// Event that is called when a user saves a report layout in the Report Designer
8283
procedure TMainForm.dxReport1LayoutChanged(ASender: TdxReport);
8384
begin
8485
DataModule1.mdLayouts.Edit;
86+
// Copy the report layout data to the BLOB field
8587
DataModule1.mdLayoutsLayout.Assign(dxReport1.Layout);
88+
// Save the report name which is not included in the layout
8689
DataModule1.mdLayoutsName.AsString := dxReport1.ReportName;
8790
DataModule1.mdLayouts.Post;
8891
end;

README.md

Lines changed: 150 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,166 @@
44
[![](https://img.shields.io/badge/📖_How_to_use_DevExpress_Examples-e9f6fc?style=flat-square)](https://docs.devexpress.com/GeneralInformation/403183)
55
[![](https://img.shields.io/badge/💬_Leave_Feedback-feecdd?style=flat-square)](#does-this-example-address-your-development-requirementsobjectives)
66
<!-- default badges end -->
7-
# DevExpress VCL Reports - Store Report Layouts in a Database
87

9-
This example stores a [report layout](https://docs.devexpress.com/VCL/dxReport.TdxReport.Layout) (XML-based template) in the BLOB field of a memory-based dataset ([TdxMemData](https://docs.devexpress.com/VCL/dxmdaset.TdxMemData) inherited from the [TDataSet](https://docwiki.embarcadero.com/Libraries/Athens/en/Data.DB.TDataSet) class shipped with the standard VCL library).
8+
# DevExpress Reports for Delphi/C++Builder – Store Report Layouts in a Database
109

11-
## Testing the example
10+
This example application stores [DevExpress report layouts][TdxReport.Layout] in a database.
11+
The application allows users to create and save report layouts, modify existing layouts, and open layouts in Report Designer/Viewer.
12+
13+
To store a DevExpress Report layout to a database, you need to store the following two properties of the [TdxReport] component:
14+
15+
- [TdxReport.Layout] – an XML-based representation of the report template.
16+
This property is a `TStringList` and requires a `TBlobField` to store.
17+
- [TdxReport.ReportName] – the internal name of the layout, not included in the layout data.
18+
This value is a `string` and can be stored in a `TWideStringField`.
19+
20+
21+
## Prerequisites
22+
23+
[DevExpress Reports Prerequisites][req]
24+
25+
[req]: https://docs.devexpress.com/VCL/405773/ExpressCrossPlatformLibrary/vcl-backend/reports-dashboards-app-deployment#vcl-reportsdashboards-prerequisites
26+
27+
28+
## Test the Example
29+
30+
- Run the sample app and click **New Report** to create an empty database record.
31+
- Click **Show Designer** to display the [Report Designer][dx-report-designer] dialog.
32+
- Create a report layout using tools available within the UI.
33+
- Click the hamburger button, select the **Save** option, and close the dialog.
34+
- Close the app. The [TdxMemData] component will store layout data in the [data.dat] file between sessions.
35+
- Run the sample app again. Click **View Designer** to load the saved report layout,
36+
or **View Report** to preview a layout-based report in the [Report Viewer][dx-report-viewer] dialog.
37+
38+
39+
## Implementation Details
40+
41+
The example uses a memory-based dataset
42+
([TdxMemData] from the DevExpress library, inherited from [TDataSet], shipped with the standard VCL library).
43+
44+
Follow the steps below to store report layouts in a database of your choice, using the corresponding `TDataSet` descendant.
45+
46+
> Note:
47+
> Applications in this example isolate data components in separate data modules: [uData.pas] (Delphi) and [uData.cpp] (C++Builder).
48+
49+
### Step 1: Create a Dataset to Store Report Layout Data
50+
51+
52+
Follow these steps to create a memory-based dataset to store report layout data:
53+
54+
1. Create a [TdxMemData] component on a form (`mdLayouts` in the example).
55+
2. Create a [TDataSource] component on a form (`dsLayouts` in the example).
56+
Assign the `TDataSource.DataSet` value to the previously created dataset component:
57+
58+
> <img src="./images/create-bind-data-source.png" style="width: 50%" alt=""/>
59+
3. Open the context menu of the dataset component and select **Field Editor…**:
60+
61+
> <img src="./images/open-context-menu.png" style="width: 50%" alt=""/>
62+
4. Click **Add…** to create a BLOB field for layout data:
63+
64+
> <img src="./images/create-layout-field.png" style="width: 50%" alt=""/>
65+
5. Click **Add…** to create a string field for layout name:
66+
67+
> <img src="./images/create-name-field.png" style="width: 50%" alt=""/>
68+
6. (Optional) Preload persistent data to the dataset.
69+
70+
You can preload persistent
71+
72+
### Step 2: Supply Layout Data to TdxReport
73+
74+
[TdxReport] requires a [Layout][TdxReport.Layout] and [ReportName][TdxReport.ReportName].
75+
Assign both properties by reading them from the dataset:
76+
77+
78+
### Step 3: Display Report Designer and Viewer
79+
80+
### Step 4: Handle Layout Changes
81+
82+
When a user edits and saves a report in the Report Designer,
83+
the value of [TdxReport.Layout] changes and a `LayoutChanged` event is called.
84+
Handle this event to save the updated layout to the active dataset record.
85+
86+
87+
```
88+
procedure TMainForm.dxReport1LayoutChanged(ASender: TdxReport);
89+
begin
90+
// Start editing the active dataset record
91+
DataModule1.mdLayouts.Edit;
92+
// Save the report layout to the database
93+
DataModule1.mdLayoutsLayout.Assign(dxReport1.Layout);
94+
// Save the report name which is not included in the layout
95+
DataModule1.mdLayoutsName.AsString := dxReport1.ReportName;
96+
// Finish editing and write a modified record
97+
DataModule1.mdLayouts.Post;
98+
end;
99+
```
100+
101+
### Step 5: Save the Database State when Application Exists
102+
103+
104+
105+
## Files to Review
106+
107+
- [uData.pas] (Delphi) and [uData.cpp] (C++Builder) read and store layout data in a database represented by an in-memory storage component.
108+
- [data.dat] stores layout data between application sessions.
109+
- [uMainForm.pas] (Delphi) and [uMainForm.cpp] (C++Builder) supply layout data from the data module to [TdxReport.Layout] and display Report Designer and Viewer.
110+
- [nwind.db] contains the Northwind sample database used as a data source for report content.
111+
112+
[uData.pas]: ./Delphi/uData.pas
113+
[uData.cpp]: ./CPB/uData.cpp
114+
[data.dat]: ./Delphi/data.dat
115+
[uMainForm.pas]: ./Delphi/uMainForm.pas
116+
[uMainForm.cpp]: ./CPB/uMainForm.cpp
117+
[nwind.db]: ./Delphi/nwind.db
12118

13-
* Run the sample app and click **New Report** to create an empty database record.
14-
* Click **Show Designer** to display the [Report Designer](https://docs.devexpress.com/XtraReports/119176/web-reporting/web-end-user-report-designer) dialog.
15-
* Create a report layout using tools available within the UI.
16-
* Click the hamburger button, select the **Save** option, and close the dialog.
17-
* Close the app. The [TdxMemData](https://docs.devexpress.com/VCL/dxmdaset.TdxMemData) component will store layout data between sessions.
18-
* Run the sample app again. Click **View Designer** to load the saved report layout, or **View Report** to preview a layout-based report in the [Report Viewer](https://docs.devexpress.com/XtraReports/401850/web-reporting/web-document-viewer) dialog.
19119

20120
## Documentation
21121

22-
* [TdxReport.Layout Property](https://docs.devexpress.com/VCL/dxReport.TdxReport.Layout)
23-
* [TdxBackendDataSetJSONConnection Component](https://docs.devexpress.com/VCL/dxBackend.ConnectionString.JSON.DataSet.TdxBackendDataSetJSONConnection)
122+
- [Introduction to VCL Reports][reports-intro]
123+
- [Tutorial: Create a table report using the Report Wizard][report-wizard]
124+
- [Use SQLite as a data source for reports (as demonstrated in the current example)][sqlite-data-source]
125+
- [Store report layouts in REPX files at design-time][reports-design-time-store]
126+
- API reference:
127+
- [TdxReport.ReportName]
128+
- [TdxReport.Layout] (an XML-based layout template that can be stored in the BLOB field of a database)
129+
- [TdxReport.ReportName]
130+
- [TdxMemData] (used to store report layout data in application runtime and between sessions)
131+
- [TDataSet] (ancestor of the `TdxMemData`, contains generic database connection methods)
132+
- [TdxBackendDatabaseSQLConnection] (used to supply data to reports)
133+
134+
<!-- documentation links -->
135+
[reports-intro]: https://docs.devexpress.com/VCL/405469/ExpressReports/vcl-reports
136+
[report-wizard]: https://docs.devexpress.com/VCL/405760/ExpressReports/getting-started/create-table-report-using-report-wizard
137+
[sqlite-data-source]: https://docs.devexpress.com/VCL/405750/ExpressCrossPlatformLibrary/vcl-backend/database-engines/vcl-backend-sqlite-support
138+
[reports-design-time-store]: https://docs.devexpress.com/VCL/dxReport.TdxReport.Layout#string-list-editor
139+
[dx-report-viewer]: https://docs.devexpress.com/XtraReports/401850/web-reporting/web-document-viewer
140+
[dx-report-designer]: https://docs.devexpress.com/XtraReports/119176/web-reporting/web-end-user-report-designer
141+
142+
143+
<!-- reference links -->
144+
[TdxReport]: https://docs.devexpress.com/VCL/dxReport.TdxReport
145+
[TdxReport.Layout]: https://docs.devexpress.com/VCL/dxReport.TdxReport.Layout
146+
[TdxReport.ReportName]: https://docs.devexpress.com/VCL/dxReport.TdxReport.ReportName
147+
[TdxBackendDatabaseSQLConnection]: https://docs.devexpress.com/VCL/dxBackend.ConnectionString.SQL.TdxBackendDatabaseSQLConnection
148+
[TdxMemData]: https://docs.devexpress.com/VCL/dxmdaset.TdxMemData
149+
150+
<!-- external documentation links -->
151+
[TDataSet]: https://docwiki.embarcadero.com/Libraries/Athens/en/Data.DB.TDataSet
152+
[TDataSource]: https://docwiki.embarcadero.com/Libraries/Athens/en/Data.DB.TDataSource
153+
<!-- in-repository links -->
154+
155+
156+
## More Examples
157+
158+
- [Store report layouts in REPX files][file-example]
159+
160+
[file-example]: https://github.com/DevExpress-Examples/vcl-reports-store-layout-template-file
161+
162+
24163
<!-- feedback -->
25164
## Does This Example Address Your Development Requirements/Objectives?
26165

27166
[<img src="https://www.devexpress.com/support/examples/i/yes-button.svg"/>](https://www.devexpress.com/support/examples/survey.xml?utm_source=github&utm_campaign=vcl-reports-store-layout-template-database&~~~was_helpful=yes) [<img src="https://www.devexpress.com/support/examples/i/no-button.svg"/>](https://www.devexpress.com/support/examples/survey.xml?utm_source=github&utm_campaign=vcl-reports-store-layout-template-database&~~~was_helpful=no)
28167

29168
(you will be redirected to DevExpress.com to submit your response)
30169
<!-- feedback end -->
31-
32-
33-

images/create-bind-data-source.png

26.7 KB
Loading

images/create-layout-field.png

33.9 KB
Loading

images/create-name-field.png

34.2 KB
Loading

images/create-persistent-data.png

13.5 KB
Loading

images/open-context-menu.png

13.1 KB
Loading

0 commit comments

Comments
 (0)