Skip to content

Commit 27d2063

Browse files
cpp-builder: Update and clarify the example
- Use correct terms: import (open) a report layout, save a report layout. - Title the file open dialog 'Import Report Layout'. - Title the file save dialog 'Save Report Layout'. - Assign proper name, icon, and title to the application. - Display the currently opened report in the application title. - Extract a method to load a report and update the application caption. - Before saving a report, pass the name to the file save dialog. - Clarify error messages in message boxes. - Fix the SQLite connection string: correct path to nwind.db. Co-authored-by: Ilia Nenashev <ilia.nenashev@devexpress.com>
1 parent b49abba commit 27d2063

9 files changed

Lines changed: 165 additions & 125 deletions
Lines changed: 61 additions & 24 deletions
Large diffs are not rendered by default.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
#include <vcl.h>
44
#pragma hdrstop
55
#include <tchar.h>
6-
//---------------------------------------------------------------------------
7-
USEFORM("uMainForm.cpp", MainForm);
6+
#include "uMainForm.h"
87
//---------------------------------------------------------------------------
98
int WINAPI _tWinMain(HINSTANCE, HINSTANCE, LPTSTR, int)
109
{
1110
try
1211
{
1312
Application->Initialize();
1413
Application->MainFormOnTaskBar = true;
14+
Application->Title = "DevExpress Example";
1515
Application->CreateForm(__classid(TMainForm), &MainForm);
1616
Application->Run();
1717
}

CPB/ReportStoreToFile_Icon.ico

26 KB
Binary file not shown.

CPB/uMainForm.cpp

Lines changed: 47 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//---------------------------------------------------------------------------
1+
//---------------------------------------------------------------------------
22

33
#include <vcl.h>
44
#pragma hdrstop
@@ -49,44 +49,70 @@
4949

5050
#pragma resource "*.dfm"
5151
TMainForm *MainForm;
52-
//---------------------------------------------------------------------------
52+
53+
const String BASE_CAPTION = "DevExpress Example — ";
54+
5355
__fastcall TMainForm::TMainForm(TComponent* Owner)
5456
: TForm(Owner)
5557
{
58+
}
5659

60+
void __fastcall TMainForm::ImportReport(const String &FileName)
61+
{
62+
if (FileExists(FileName))
63+
{
64+
// Load a report layout from a file
65+
dxReport1->Layout->LoadFromFile(FileName);
66+
// Assign the loaded file's name as an internal report name
67+
dxReport1->ReportName = ChangeFileExt(ExtractFileName(FileName), "");
68+
// Update the form caption based on the report name
69+
Caption = BASE_CAPTION + dxReport1->ReportName;
70+
}
71+
else
72+
{
73+
ShowMessage("The specified file could not be found: " + FileName);
74+
}
75+
}
76+
77+
void __fastcall TMainForm::FormCreate(TObject *Sender)
78+
{
79+
// Assumes that the compiled executable is located in ./Delphi/Win*/[Debug|Release]/
80+
const String AFileName = "..\\..\\..\\Table Report.repx";
81+
ImportReport(AFileName);
5782
}
58-
//---------------------------------------------------------------------
5983

6084
void __fastcall TMainForm::btnNewClick(TObject *Sender)
6185
{
62-
Caption = "";
86+
Caption = BASE_CAPTION + "New Report Layout";
6387
dxReport1->ReportName = "";
6488
dxReport1->ShowDesigner();
6589
}
6690

67-
void __fastcall TMainForm::btnOpenClick(TObject *Sender)
91+
void __fastcall TMainForm::btnImportClick(TObject *Sender)
6892
{
6993
if (dxOpenFileDialog->Execute())
7094
{
71-
Caption = ChangeFileExt(ExtractFileName(dxOpenFileDialog->FileName), "");
72-
dxReport1->ReportName = Caption;
73-
dxReport1->Layout->LoadFromFile(dxOpenFileDialog->FileName);
95+
ImportReport(dxOpenFileDialog->FileName);
7496
}
7597
}
7698

77-
void __fastcall TMainForm::btnSaveClick(TObject *Sender)
99+
void __fastcall TMainForm::btnSaveToFileClick(TObject *Sender)
78100
{
79-
if (dxReport1->ReportName == "")
101+
if (dxReport1->ReportName.IsEmpty())
80102
{
81-
ShowMessage("Report is not specified");
103+
ShowMessage("No report is currently open. Please import or create a new report before exporting.");
82104
return;
83105
}
84-
106+
// Suggest a file name based on the report name
107+
dxSaveFileDialog->FileName = dxReport1->ReportName;
85108
if (dxSaveFileDialog->Execute())
86-
{
109+
{
110+
// Update the report name based on the selected file name
87111
dxReport1->ReportName = ChangeFileExt(ExtractFileName(dxSaveFileDialog->FileName), "");
88-
Caption = dxReport1->ReportName;
89-
dxReport1->Layout->SaveToFile(dxSaveFileDialog->FileName);
112+
// Save the report layout to a file
113+
dxReport1->Layout->SaveToFile(dxSaveFileDialog->FileName);
114+
// Update the form caption based on the report name
115+
Caption = BASE_CAPTION + dxReport1->ReportName;
90116
}
91117
}
92118

@@ -95,35 +121,17 @@ void __fastcall TMainForm::btnDesignClick(TObject *Sender)
95121
dxReport1->ShowDesigner();
96122
}
97123

98-
//---------------------------------------------------------------------------
99-
100124
void __fastcall TMainForm::btnPreviewClick(TObject *Sender)
101125
{
102126
if (dxReport1->ReportName == "")
103-
{
104-
ShowMessage("Report is not specified");
105-
return;
106-
}
107-
dxReport1->ShowViewer();
127+
{
128+
ShowMessage("No report is currently loaded. Please load or create a report before previewing.");
129+
return;
130+
}
131+
dxReport1->ShowViewer();
108132
}
109133
void __fastcall TMainForm::dxReport1LayoutChanged(TdxReport *ASender)
110134
{
111-
Caption = dxReport1->ReportName;
112-
}
113-
114-
//---------------------------------------------------------------------------
115-
116-
void __fastcall TMainForm::FormCreate(TObject *Sender)
117-
{
118-
const String AFileName = "..\\..\\..\\TableReport.repx";
119-
if (FileExists(AFileName))
120-
{
121-
dxReport1->ReportName = "TableReport";
122-
dxReport1->Layout->LoadFromFile(AFileName);
123-
}
135+
Caption = BASE_CAPTION + dxReport1->ReportName;
124136
}
125-
//---------------------------------------------------------------------------
126-
127-
128-
//---------------------------------------------------------------------------
129137

CPB/uMainForm.dfm

Lines changed: 49 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
object MainForm: TMainForm
22
Left = 0
33
Top = 0
4+
Width = 577
5+
Height = 312
6+
AutoScroll = True
47
AutoSize = True
58
Caption = 'MainForm'
6-
ClientHeight = 297
7-
ClientWidth = 465
89
Color = clBtnFace
910
Font.Charset = DEFAULT_CHARSET
1011
Font.Color = clWindowText
@@ -16,61 +17,60 @@ object MainForm: TMainForm
1617
object dxLayoutControl1: TdxLayoutControl
1718
Left = 0
1819
Top = 0
19-
Width = 465
20-
Height = 297
20+
Width = 561
21+
Height = 273
2122
TabOrder = 0
2223
AutoSize = True
23-
object btnOpen: TcxButton
24-
Left = 12
25-
Top = 44
24+
CustomizeFormTabbedView = True
25+
object btnImport: TcxButton
26+
Left = 26
27+
Top = 83
2628
Width = 145
2729
Height = 25
28-
Caption = 'Open Report'
29-
SpeedButtonOptions.CanBeFocused = False
30+
Caption = 'Import from File'
3031
TabOrder = 1
31-
OnClick = btnOpenClick
32+
OnClick = btnImportClick
3233
end
3334
object btnPreview: TcxButton
34-
Left = 164
35-
Top = 75
35+
Left = 206
36+
Top = 82
3637
Width = 193
3738
Height = 25
38-
Caption = 'Preview Report'
39+
Caption = 'Open Viewer'
3940
TabOrder = 4
4041
OnClick = btnPreviewClick
4142
end
4243
object btnNew: TcxButton
43-
Left = 12
44-
Top = 12
44+
Left = 26
45+
Top = 51
4546
Width = 145
4647
Height = 25
47-
Caption = 'New Report'
48+
Caption = 'Create New'
4849
TabOrder = 0
4950
OnClick = btnNewClick
5051
end
51-
object btnSave: TcxButton
52-
Left = 164
53-
Top = 12
54-
Width = 193
52+
object btnSaveToFile: TcxButton
53+
Left = 26
54+
Top = 115
55+
Width = 145
5556
Height = 25
56-
Caption = 'Save Report'
57+
Caption = 'Save to File'
5758
TabOrder = 2
58-
OnClick = btnSaveClick
59+
OnClick = btnSaveToFileClick
5960
end
6061
object btnDesign: TcxButton
61-
Left = 164
62-
Top = 44
62+
Left = 206
63+
Top = 51
6364
Width = 193
6465
Height = 24
65-
Caption = 'Design Report'
66+
Caption = 'Open Designer'
6667
TabOrder = 3
6768
OnClick = btnDesignClick
6869
end
6970
object dxLayoutControl1Group_Root: TdxLayoutGroup
7071
AlignHorz = ahLeft
7172
AlignVert = avTop
7273
Hidden = True
73-
ItemIndex = 1
7474
LayoutDirection = ldHorizontal
7575
ShowBorder = False
7676
Index = -1
@@ -91,21 +91,21 @@ object MainForm: TMainForm
9191
AlignVert = avTop
9292
CaptionOptions.Text = 'btnOpen'
9393
CaptionOptions.Visible = False
94-
Control = btnOpen
94+
Control = btnImport
9595
ControlOptions.OriginalHeight = 25
9696
ControlOptions.OriginalWidth = 145
9797
ControlOptions.ShowBorder = False
9898
Index = 1
9999
end
100100
object liSave: TdxLayoutItem
101-
Parent = dxLayoutGroup2
101+
Parent = dxLayoutGroup1
102102
CaptionOptions.Text = 'btnSave'
103103
CaptionOptions.Visible = False
104-
Control = btnSave
104+
Control = btnSaveToFile
105105
ControlOptions.OriginalHeight = 25
106106
ControlOptions.OriginalWidth = 145
107107
ControlOptions.ShowBorder = False
108-
Index = 0
108+
Index = 2
109109
end
110110
object liDesign: TdxLayoutItem
111111
Parent = dxLayoutGroup2
@@ -115,7 +115,7 @@ object MainForm: TMainForm
115115
ControlOptions.OriginalHeight = 24
116116
ControlOptions.OriginalWidth = 193
117117
ControlOptions.ShowBorder = False
118-
Index = 1
118+
Index = 0
119119
end
120120
object liPreview: TdxLayoutItem
121121
Parent = dxLayoutGroup2
@@ -125,7 +125,7 @@ object MainForm: TMainForm
125125
ControlOptions.OriginalHeight = 25
126126
ControlOptions.OriginalWidth = 193
127127
ControlOptions.ShowBorder = False
128-
Index = 2
128+
Index = 1
129129
end
130130
object dxLayoutLabeledItem1: TdxLayoutLabeledItem
131131
CaptionOptions.Text = 'Label'
@@ -134,53 +134,47 @@ object MainForm: TMainForm
134134
object dxLayoutGroup1: TdxLayoutGroup
135135
Parent = dxLayoutControl1Group_Root
136136
AlignHorz = ahClient
137-
CaptionOptions.Text = 'New Group'
138-
CaptionOptions.Visible = False
139-
ItemIndex = 1
140-
ShowBorder = False
137+
CaptionOptions.Text = 'Report Layout'
141138
Index = 0
142139
end
143140
object dxLayoutGroup2: TdxLayoutGroup
144141
Parent = dxLayoutControl1Group_Root
145-
AlignHorz = ahClient
146-
CaptionOptions.Text = 'New Group'
147-
CaptionOptions.Visible = False
148-
ItemIndex = 2
149-
ShowBorder = False
142+
CaptionOptions.Text = 'Report Dialogs'
150143
Index = 1
151144
end
152145
end
153146
object dxReport1: TdxReport
154147
Parameters = <>
155148
OnLayoutChanged = dxReport1LayoutChanged
156-
Left = 48
157-
Top = 214
149+
Left = 16
150+
Top = 224
158151
end
159152
object dxOpenFileDialog: TdxOpenFileDialog
160153
Filter = 'REPX (*.repx)|*.repx'
161154
Options = [ofHideReadOnly, ofPathMustExist, ofFileMustExist, ofEnableSizing]
162-
Left = 152
163-
Top = 160
155+
Title = 'Import Report Layout'
156+
Left = 136
157+
Top = 176
164158
end
165159
object dxSaveFileDialog: TdxSaveFileDialog
166160
DefaultExt = 'repx'
167161
Filter = 'REPX (*.repx)|*.repx'
168-
Left = 96
169-
Top = 160
162+
Title = 'Save Report Layout'
163+
Left = 72
164+
Top = 176
170165
end
171-
object dxBackendDataConnectionManager1: TdxBackendDataConnectionManager
172-
Left = 48
173-
Top = 160
166+
object dxBackendDataConnectionManager: TdxBackendDataConnectionManager
167+
Left = 16
168+
Top = 176
174169
object ReportsNWindConnectionString: TdxBackendDatabaseSQLConnection
175170
DisplayName = 'NWindConnectionString'
176-
ConnectionString =
177-
'XpoProvider=SQLite; Data Source=|DataDirectory|\..\..\..\nwind.d' +
178-
'b; Mode=ReadOnly'
171+
ConnectionString = 'XpoProvider=SQLite; Data Source=..\..\..\nwind.db; Mode=ReadOnly'
179172
end
180173
end
181174
object dxSkinController1: TdxSkinController
175+
NativeStyle = False
182176
SkinName = 'WXI'
183-
Left = 96
184-
Top = 214
177+
Left = 72
178+
Top = 224
185179
end
186180
end

0 commit comments

Comments
 (0)