Skip to content

Commit d08c196

Browse files
committed
delphi: Switch languages using TcxRadioButtons
TcxRadioButtons better represent application state than simple buttons. - Use the German localization language when application starts. - Use TcxRadioButtons to switch localization languages. - Check the "German" radiobutton to reflect the default localization. - Group "Display Report" buttons into a labeled group. - Move focus to "Display Report Designer" button when application starts. - Forbid to resize the application form. - Give the application a relevant title. - Put example data grid into a labeled group. squash
1 parent fa8f1e9 commit d08c196

2 files changed

Lines changed: 157 additions & 123 deletions

File tree

Delphi/uMainForm.dfm

Lines changed: 136 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -1,135 +1,160 @@
11
object MainForm: TMainForm
22
Left = 0
33
Top = 0
4-
Caption = 'MainForm'
5-
ClientHeight = 483
6-
ClientWidth = 606
4+
BorderIcons = [biSystemMenu, biMinimize, biHelp]
5+
BorderStyle = bsSingle
6+
Caption = 'DevExpress Reports Localization Example'
7+
ClientHeight = 399
8+
ClientWidth = 558
79
Color = clBtnFace
810
Font.Charset = DEFAULT_CHARSET
911
Font.Color = clWindowText
1012
Font.Height = -12
1113
Font.Name = 'Segoe UI'
1214
Font.Style = []
15+
OnCreate = FormCreate
1316
TextHeight = 15
14-
object btnShowDesigner: TcxButton
15-
Left = 24
16-
Top = 32
17-
Width = 145
18-
Height = 25
19-
Caption = 'Show Designer'
20-
TabOrder = 0
21-
OnClick = btnShowDesignerClick
22-
end
23-
object btnViewReport: TcxButton
24-
Left = 192
25-
Top = 32
26-
Width = 193
27-
Height = 25
28-
Caption = 'View Report'
29-
TabOrder = 1
30-
OnClick = btnViewReportClick
31-
end
32-
object cxGrid1: TcxGrid
33-
Left = 24
34-
Top = 176
35-
Width = 521
36-
Height = 265
17+
object cxGroupBox2: TcxGroupBox
18+
Left = 8
19+
Top = 110
20+
Caption = 'Example Data Source'
3721
TabOrder = 2
38-
object gvCategories: TcxGridDBTableView
39-
DataController.DataSource = DataModule1.dsCategories
40-
DataController.KeyFieldNames = 'CategoryID'
41-
object gvCategoriesCategoryID: TcxGridDBColumn
42-
DataBinding.FieldName = 'CategoryID'
43-
end
44-
object gvCategoriesCategoryName: TcxGridDBColumn
45-
DataBinding.FieldName = 'CategoryName'
46-
end
47-
object gvCategoriesDescription: TcxGridDBColumn
48-
DataBinding.FieldName = 'Description'
22+
Height = 277
23+
Width = 537
24+
object cxGrid1: TcxGrid
25+
Left = 16
26+
Top = 24
27+
Width = 505
28+
Height = 241
29+
TabOrder = 0
30+
DragOpening = False
31+
object gvCategories: TcxGridDBTableView
32+
DataController.DataSource = DataModule1.dsCategories
33+
DataController.KeyFieldNames = 'CategoryID'
34+
object gvCategoriesCategoryID: TcxGridDBColumn
35+
DataBinding.FieldName = 'CategoryID'
36+
end
37+
object gvCategoriesCategoryName: TcxGridDBColumn
38+
DataBinding.FieldName = 'CategoryName'
39+
end
40+
object gvCategoriesDescription: TcxGridDBColumn
41+
DataBinding.FieldName = 'Description'
42+
end
43+
end
44+
object gvProducts: TcxGridDBTableView
45+
DataController.DataSource = DataModule1.dsProducts
46+
DataController.DetailKeyFieldNames = 'CategoryID'
47+
DataController.KeyFieldNames = 'ProductID'
48+
DataController.MasterKeyFieldNames = 'CategoryID'
49+
object gvProductsProductID: TcxGridDBColumn
50+
DataBinding.FieldName = 'ProductID'
51+
end
52+
object gvProductsProductName: TcxGridDBColumn
53+
DataBinding.FieldName = 'ProductName'
54+
Width = 244
55+
end
56+
object gvProductsSupplierID: TcxGridDBColumn
57+
DataBinding.FieldName = 'SupplierID'
58+
end
59+
object gvProductsCategoryID: TcxGridDBColumn
60+
DataBinding.FieldName = 'CategoryID'
61+
end
62+
object gvProductsQuantityPerUnit: TcxGridDBColumn
63+
DataBinding.FieldName = 'QuantityPerUnit'
64+
Width = 124
65+
end
66+
object gvProductsUnitPrice: TcxGridDBColumn
67+
DataBinding.FieldName = 'UnitPrice'
68+
end
69+
object gvProductsUnitsInStock: TcxGridDBColumn
70+
DataBinding.FieldName = 'UnitsInStock'
71+
end
72+
object gvProductsUnitsOnOrder: TcxGridDBColumn
73+
DataBinding.FieldName = 'UnitsOnOrder'
74+
end
75+
object gvProductsReorderLevel: TcxGridDBColumn
76+
DataBinding.FieldName = 'ReorderLevel'
77+
end
78+
object gvProductsDiscontinued: TcxGridDBColumn
79+
DataBinding.FieldName = 'Discontinued'
80+
Width = 34
81+
end
82+
object gvProductsEAN13: TcxGridDBColumn
83+
DataBinding.FieldName = 'EAN13'
84+
Width = 76
85+
end
86+
end
87+
object cxGrid1Level1: TcxGridLevel
88+
GridView = gvCategories
89+
object cxGrid1Level2: TcxGridLevel
90+
GridView = gvProducts
91+
end
4992
end
5093
end
51-
object gvProducts: TcxGridDBTableView
52-
DataController.DataSource = DataModule1.dsProducts
53-
DataController.DetailKeyFieldNames = 'CategoryID'
54-
DataController.KeyFieldNames = 'ProductID'
55-
DataController.MasterKeyFieldNames = 'CategoryID'
56-
object gvProductsProductID: TcxGridDBColumn
57-
DataBinding.FieldName = 'ProductID'
58-
end
59-
object gvProductsProductName: TcxGridDBColumn
60-
DataBinding.FieldName = 'ProductName'
61-
Width = 244
62-
end
63-
object gvProductsSupplierID: TcxGridDBColumn
64-
DataBinding.FieldName = 'SupplierID'
65-
end
66-
object gvProductsCategoryID: TcxGridDBColumn
67-
DataBinding.FieldName = 'CategoryID'
68-
end
69-
object gvProductsQuantityPerUnit: TcxGridDBColumn
70-
DataBinding.FieldName = 'QuantityPerUnit'
71-
Width = 124
72-
end
73-
object gvProductsUnitPrice: TcxGridDBColumn
74-
DataBinding.FieldName = 'UnitPrice'
75-
end
76-
object gvProductsUnitsInStock: TcxGridDBColumn
77-
DataBinding.FieldName = 'UnitsInStock'
78-
end
79-
object gvProductsUnitsOnOrder: TcxGridDBColumn
80-
DataBinding.FieldName = 'UnitsOnOrder'
81-
end
82-
object gvProductsReorderLevel: TcxGridDBColumn
83-
DataBinding.FieldName = 'ReorderLevel'
84-
end
85-
object gvProductsDiscontinued: TcxGridDBColumn
86-
DataBinding.FieldName = 'Discontinued'
87-
Width = 34
88-
end
89-
object gvProductsEAN13: TcxGridDBColumn
90-
DataBinding.FieldName = 'EAN13'
91-
Width = 76
92-
end
94+
end
95+
object cxGroupBox1: TcxGroupBox
96+
Left = 211
97+
Top = 17
98+
Caption = 'Display a Localized Report Dialog:'
99+
TabOrder = 1
100+
Height = 86
101+
Width = 192
102+
object btnViewReport: TcxButton
103+
Left = 15
104+
Top = 52
105+
Width = 145
106+
Height = 25
107+
Caption = 'Report Viewer'
108+
TabOrder = 1
109+
OnClick = btnViewReportClick
93110
end
94-
object cxGrid1Level1: TcxGridLevel
95-
GridView = gvCategories
96-
object cxGrid1Level2: TcxGridLevel
97-
GridView = gvProducts
98-
end
111+
object btnShowDesigner: TcxButton
112+
Left = 15
113+
Top = 21
114+
Width = 145
115+
Height = 25
116+
Caption = 'Report Designer'
117+
TabOrder = 0
118+
OnClick = btnShowDesignerClick
99119
end
100120
end
101-
object btnSetLanguageUS: TcxButton
102-
Left = 72
103-
Top = 88
104-
Width = 121
105-
Height = 25
106-
Caption = 'English'
107-
TabOrder = 3
108-
OnClick = btnSetLanguageUSClick
109-
end
110-
object btnSetLanguageDE: TcxButton
111-
Left = 199
112-
Top = 88
113-
Width = 131
114-
Height = 25
115-
Caption = 'German'
116-
TabOrder = 4
117-
OnClick = btnSetLanguageDEClick
118-
end
119-
object lblSelectLanguage: TcxLabel
120-
Left = 56
121-
Top = 64
122-
Caption = 'Select Language'
123-
TabOrder = 5
121+
object cxRadioGroup1: TcxRadioGroup
122+
Left = 8
123+
Top = 17
124+
Caption = 'Localize Report Dialogs in:'
125+
Properties.Items = <>
126+
TabOrder = 0
127+
Height = 86
128+
Width = 185
129+
object cxRadioButton1: TcxRadioButton
130+
Left = 16
131+
Top = 25
132+
Width = 113
133+
Height = 17
134+
Caption = 'English (en-US)'
135+
TabOrder = 0
136+
OnClick = cxRadioButton1Click
137+
end
138+
object cxRadioButton2: TcxRadioButton
139+
Left = 16
140+
Top = 56
141+
Width = 113
142+
Height = 17
143+
Caption = 'German (de-DE)'
144+
Checked = True
145+
TabOrder = 1
146+
TabStop = True
147+
OnClick = cxRadioButton2Click
148+
end
124149
end
125150
object dxReport1: TdxReport
126151
Parameters = <>
127-
Left = 48
128-
Top = 128
152+
Left = 416
153+
Top = 32
129154
end
130155
object dxBackendDataConnectionManager1: TdxBackendDataConnectionManager
131-
Left = 112
132-
Top = 128
156+
Left = 472
157+
Top = 32
133158
object dxBackendDataConnectionManager1dxBackendDataSetJSONConnection1: TdxBackendDataSetJSONConnection
134159
DisplayName = 'DataSetConnection'
135160
object itmProducts: TdxBackendDataSetCollectionItem

Delphi/uMainForm.pas

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ interface
1212
cxGridTableView, cxGridDBTableView, cxGrid, FireDAC.Comp.DataSet,
1313
FireDAC.Comp.Client, dxBackend.ConnectionString.JSON.DataSet,
1414
dxBackend.ConnectionString.JSON, Vcl.StdCtrls, dxmdaset, uData, cxContainer,
15-
cxLabel;
15+
cxLabel, cxRadioGroup, cxGroupBox;
1616

1717
type
1818
TMainForm = class(TForm)
@@ -42,13 +42,16 @@ TMainForm = class(TForm)
4242
gvProductsEAN13: TcxGridDBColumn;
4343
cxGrid1Level1: TcxGridLevel;
4444
cxGrid1Level2: TcxGridLevel;
45-
btnSetLanguageUS: TcxButton;
46-
btnSetLanguageDE: TcxButton;
47-
lblSelectLanguage: TcxLabel;
45+
cxRadioGroup1: TcxRadioGroup;
46+
cxRadioButton1: TcxRadioButton;
47+
cxRadioButton2: TcxRadioButton;
48+
cxGroupBox1: TcxGroupBox;
49+
cxGroupBox2: TcxGroupBox;
50+
procedure FormCreate(Sender: TObject);
4851
procedure btnShowDesignerClick(Sender: TObject);
4952
procedure btnViewReportClick(Sender: TObject);
50-
procedure btnSetLanguageUSClick(Sender: TObject);
51-
procedure btnSetLanguageDEClick(Sender: TObject);
53+
procedure cxRadioButton1Click(Sender: TObject);
54+
procedure cxRadioButton2Click(Sender: TObject);
5255
private
5356
{ Private declarations }
5457
public
@@ -62,14 +65,10 @@ implementation
6265

6366
{$R *.dfm}
6467

65-
procedure TMainForm.btnSetLanguageDEClick(Sender: TObject);
66-
begin
67-
dxReport1.Language := 'de-DE'
68-
end;
6968

70-
procedure TMainForm.btnSetLanguageUSClick(Sender: TObject);
69+
procedure TMainForm.FormCreate(Sender: TObject);
7170
begin
72-
dxReport1.Language := 'en-US'
71+
dxReport1.Language := 'de-DE';
7372
end;
7473

7574
procedure TMainForm.btnShowDesignerClick(Sender: TObject);
@@ -82,4 +81,14 @@ procedure TMainForm.btnViewReportClick(Sender: TObject);
8281
dxReport1.ShowViewer;
8382
end;
8483

84+
procedure TMainForm.cxRadioButton1Click(Sender: TObject);
85+
begin
86+
dxReport1.Language := 'en-US';
87+
end;
88+
89+
procedure TMainForm.cxRadioButton2Click(Sender: TObject);
90+
begin
91+
dxReport1.Language := 'de-DE';
92+
end;
93+
8594
end.

0 commit comments

Comments
 (0)