-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdlgPref.pas
174 lines (154 loc) · 4.39 KB
/
dlgPref.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
unit dlgPref;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ComCtrls,
Vcl.ExtCtrls,
Vcl.Samples.Spin, System.ImageList, Vcl.ImgList, Vcl.VirtualImageList,
Vcl.BaseImageCollection, Vcl.ImageCollection;
type
TPref = class(TForm)
Panel1: TPanel;
Panel2: TPanel;
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
edtMembership: TEdit;
Label2: TLabel;
FileOpenDialog: TFileOpenDialog;
btnClose: TButton;
Label1: TLabel;
edtGold: TEdit;
btnGold: TButton;
sedtMaxAllowToPick: TSpinEdit;
Label3: TLabel;
Label4: TLabel;
edtSilver: TEdit;
Label5: TLabel;
edtBronze: TEdit;
ImageCollection1: TImageCollection;
VirtualImageList1: TVirtualImageList;
btnSilver: TButton;
btnBronze: TButton;
btnMembership: TButton;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure btnPodiumCertifClick(Sender: TObject);
procedure btnMemshipClick(Sender: TObject);
procedure btnCloseClick(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
private
{ Private declarations }
// P R E F E R E N C E F I L E A C C E S S .
procedure ReadPreferences(iniFileName: string);
procedure WritePreferences(iniFileName: string);
public
{ Public declarations }
end;
var
Pref: TPref;
implementation
{$R *.dfm}
uses
IniFiles, Utility, System.UITypes;
{ TPref }
procedure TPref.btnPodiumCertifClick(Sender: TObject);
var
s: string;
i: integer;
begin
i := (Sender as TButton).Tag;
case i of
1:
s := ExtractFilePath(edtGold.Text);
2:
s := ExtractFilePath(edtSilver.Text);
3:
s := ExtractFilePath(edtBronze.Text);
end;
s := ExtractFilePath(edtGold.Text);
FileOpenDialog.DefaultFolder := s;
if FileOpenDialog.Execute then
begin
case i of
1:
edtGold.Text := FileOpenDialog.FileName;
2:
edtSilver.Text := FileOpenDialog.FileName;
3:
edtBronze.Text := FileOpenDialog.FileName;
end;
end;
end;
procedure TPref.btnMemshipClick(Sender: TObject);
var
s: string;
begin
s := ExtractFilePath(edtMembership.Text);
FileOpenDialog.DefaultFolder := s;
if FileOpenDialog.Execute then
begin
edtMembership.Text := FileOpenDialog.FileName;
end;
end;
procedure TPref.btnCloseClick(Sender: TObject);
begin
ModalResult := mrOk;
end;
procedure TPref.FormCreate(Sender: TObject);
var
iniFileName: string;
begin
// read from preference file
iniFileName := GetSCMPreferenceFileName();
if FileExists(iniFileName) then
ReadPreferences(iniFileName)
else
begin
// SCM SYSTEM ERROR : The preference file couldn't be created.
MessageDlg('An unexpected SCM error occurred.' + sLineBreak +
'Unable to read SCM_MoreReportsPref.ini.', mtError, [mbOk], 0);
end;
end;
procedure TPref.FormDestroy(Sender: TObject);
var
iniFileName: string;
begin
// write out values
iniFileName := GetSCMPreferenceFileName();
if FileExists(iniFileName) then
WritePreferences(iniFileName);
end;
procedure TPref.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
if Key = VK_ESCAPE then
ModalResult := mrCancel;
end;
procedure TPref.ReadPreferences(iniFileName: string);
var
iFile: TIniFile;
begin
iFile := TIniFile.create(iniFileName);
edtGold.Text := iFile.ReadString(IniSectionName, 'CustRptCertifGOLD', '');
edtSilver.Text := iFile.ReadString(IniSectionName, 'CustRptCertifSILVER', '');
edtBronze.Text := iFile.ReadString(IniSectionName, 'CustRptCertifBRONZE', '');
edtMembership.Text := iFile.ReadString(IniSectionName, 'CustRptMemShip', '');
sedtMaxAllowToPick.Value := iFile.ReadInteger(IniSectionName,
'MaxAllowToPick', 20);
iFile.Free;
end;
procedure TPref.WritePreferences(iniFileName: string);
var
iFile: TIniFile;
begin
iFile := TIniFile.create(iniFileName);
iFile.WriteInteger(IniSectionName, 'MaxAllowToPick',
sedtMaxAllowToPick.Value);
iFile.WriteString(IniSectionName, 'CustRptCertifGOLD', edtGold.Text);
iFile.WriteString(IniSectionName, 'CustRptCertifSILVER', edtSilver.Text);
iFile.WriteString(IniSectionName, 'CustRptCertifBRONZE', edtBronze.Text);
iFile.WriteString(IniSectionName, 'CustRptMemShip', edtMembership.Text);
iFile.Free;
end;
end.