root / UnitOptions.pas
Historique | Voir | Annoter | Télécharger (7,655 ko)
1 | 1 | avalancogn | unit UnitOptions;
|
---|---|---|---|
2 | |||
3 | interface
|
||
4 | |||
5 | uses
|
||
6 | Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, |
||
7 | Dialogs, StdCtrls, ExtCtrls, Registry, gnugettext, ImgList, ActnList, |
||
8 | JvExStdCtrls, JvButton, JvCtrls; |
||
9 | |||
10 | type
|
||
11 | TFormOptions = class(TForm)
|
||
12 | LabelExpression: TLabel; |
||
13 | LabelProximal: TLabel; |
||
14 | LabelEnergy: TLabel; |
||
15 | LabelAA: TLabel; |
||
16 | LabelIncorporation: TLabel; |
||
17 | LabelMinerals: TLabel; |
||
18 | ComboBoxExpression: TComboBox; |
||
19 | ComboBoxProximal: TComboBox; |
||
20 | ComboBoxEnergy: TComboBox; |
||
21 | ComboBoxAA: TComboBox; |
||
22 | ComboBoxIncorporation: TComboBox; |
||
23 | ComboBoxMinerals: TComboBox; |
||
24 | JvImgBtnCancel: TJvImgBtn; |
||
25 | JvImgBtnOK: TJvImgBtn; |
||
26 | JvImgBtnHelp: TJvImgBtn; |
||
27 | ActionListButtons: TActionList; |
||
28 | ActionHelp: TAction; |
||
29 | ActionOK: TAction; |
||
30 | ActionCancel: TAction; |
||
31 | ImageListIcons: TImageList; |
||
32 | PanelButtons: TPanel; |
||
33 | procedure FormCreate(Sender: TObject);
|
||
34 | procedure FormShow(Sender: TObject);
|
||
35 | procedure FormDestroy(Sender: TObject);
|
||
36 | procedure ActionHelpExecute(Sender: TObject);
|
||
37 | procedure ActionOKExecute(Sender: TObject);
|
||
38 | procedure ActionCancelExecute(Sender: TObject);
|
||
39 | private
|
||
40 | { D?clarations priv?es }
|
||
41 | public
|
||
42 | { D?clarations publiques }
|
||
43 | Reg: TRegistry; |
||
44 | OptionChanged: Boolean; |
||
45 | Expression, Proximal, Energy, AA, Minerals, Incorporation: Integer; |
||
46 | ProximalDecimals, EnergyDecimals, AADecimals, MineralsDecimals, IncorporationDecimals: Integer; |
||
47 | ProximalFormat, EnergyFormat, AAFormat, MineralsFormat, IncorporationFormat: String;
|
||
48 | CurrentLanguage: string;
|
||
49 | MainLeft, MainTop, MainWidth, MainHeight: Integer; |
||
50 | procedure AjustProximal;
|
||
51 | procedure AjustEnergy;
|
||
52 | procedure AjustAA;
|
||
53 | procedure AjustMinerals;
|
||
54 | procedure AjustIncorporation;
|
||
55 | function DecimalFormat(Decimals: Integer): String; |
||
56 | end;
|
||
57 | |||
58 | var
|
||
59 | FormOptions: TFormOptions; |
||
60 | |||
61 | implementation
|
||
62 | |||
63 | {$R *.dfm}
|
||
64 | |||
65 | procedure TFormOptions.AjustProximal;
|
||
66 | begin
|
||
67 | if Proximal = 1 |
||
68 | then // g/kg |
||
69 | ProximalDecimals := 1
|
||
70 | else // % |
||
71 | ProximalDecimals := 2;
|
||
72 | ProximalFormat := DecimalFormat(ProximalDecimals); |
||
73 | end;
|
||
74 | |||
75 | procedure TFormOptions.AjustEnergy;
|
||
76 | begin
|
||
77 | if Energy = 1 |
||
78 | then // kcal/kg |
||
79 | EnergyDecimals := 0
|
||
80 | else // MJ/kg |
||
81 | EnergyDecimals := 2;
|
||
82 | EnergyFormat := DecimalFormat(EnergyDecimals); |
||
83 | end;
|
||
84 | |||
85 | procedure TFormOptions.ActionCancelExecute(Sender: TObject);
|
||
86 | begin
|
||
87 | ModalResult := mrCancel; |
||
88 | end;
|
||
89 | |||
90 | procedure TFormOptions.ActionHelpExecute(Sender: TObject);
|
||
91 | begin
|
||
92 | Application.HelpContext(HelpContext); |
||
93 | end;
|
||
94 | |||
95 | procedure TFormOptions.ActionOKExecute(Sender: TObject);
|
||
96 | begin
|
||
97 | OptionChanged := False; |
||
98 | if ComboBoxExpression.ItemIndex <> Expression
|
||
99 | then
|
||
100 | begin
|
||
101 | OptionChanged := True; |
||
102 | Expression := ComboBoxExpression.ItemIndex; |
||
103 | end;
|
||
104 | if ComboBoxProximal.ItemIndex <> Proximal
|
||
105 | then
|
||
106 | begin
|
||
107 | OptionChanged := True; |
||
108 | Proximal := ComboBoxProximal.ItemIndex; |
||
109 | AjustProximal; |
||
110 | end;
|
||
111 | if ComboBoxEnergy.ItemIndex <> Energy
|
||
112 | then
|
||
113 | begin
|
||
114 | OptionChanged := True; |
||
115 | Energy := ComboBoxEnergy.ItemIndex; |
||
116 | AjustEnergy; |
||
117 | end;
|
||
118 | if ComboBoxAA.ItemIndex <> AA
|
||
119 | then
|
||
120 | begin
|
||
121 | OptionChanged := True; |
||
122 | AA := ComboBoxAA.ItemIndex; |
||
123 | AjustAA; |
||
124 | end;
|
||
125 | if ComboBoxMinerals.ItemIndex <> Minerals
|
||
126 | then
|
||
127 | begin
|
||
128 | OptionChanged := True; |
||
129 | Minerals := ComboBoxMinerals.ItemIndex; |
||
130 | AjustMinerals; |
||
131 | end;
|
||
132 | if ComboBoxIncorporation.ItemIndex <> Incorporation
|
||
133 | then
|
||
134 | begin
|
||
135 | OptionChanged := True; |
||
136 | Incorporation := ComboBoxIncorporation.ItemIndex; |
||
137 | AjustIncorporation; |
||
138 | end;
|
||
139 | if OptionChanged
|
||
140 | then // Sauvegarder la configuration |
||
141 | begin
|
||
142 | Reg.Access := KEY_WRITE; |
||
143 | if Reg.OpenKey('\Software\EvaPig2020', True) |
||
144 | then
|
||
145 | begin
|
||
146 | Reg.WriteInteger('GeneralExpression', Expression);
|
||
147 | Reg.WriteInteger('ProximalAnalysis', Proximal);
|
||
148 | Reg.WriteInteger('EnergyValues', Energy);
|
||
149 | Reg.WriteInteger('AminoAcids', AA);
|
||
150 | Reg.WriteInteger('Minerals', Minerals);
|
||
151 | Reg.WriteInteger('IncorporationLevel', Incorporation);
|
||
152 | Reg.CloseKey; |
||
153 | end;
|
||
154 | end;
|
||
155 | ModalResult := mrOk; |
||
156 | end;
|
||
157 | |||
158 | procedure TFormOptions.AjustAA;
|
||
159 | begin
|
||
160 | if AA = 1 |
||
161 | then // g/kg |
||
162 | AADecimals := 1
|
||
163 | else // % |
||
164 | AADecimals := 2;
|
||
165 | AAFormat := DecimalFormat(AADecimals); |
||
166 | end;
|
||
167 | |||
168 | procedure TFormOptions.AjustMinerals;
|
||
169 | begin
|
||
170 | if Minerals = 1 |
||
171 | then // g/kg |
||
172 | MineralsDecimals := 2
|
||
173 | else // % |
||
174 | MineralsDecimals := 3;
|
||
175 | MineralsFormat := DecimalFormat(MineralsDecimals); |
||
176 | end;
|
||
177 | |||
178 | procedure TFormOptions.AjustIncorporation;
|
||
179 | begin
|
||
180 | if Incorporation = 1 |
||
181 | then // g/kg |
||
182 | IncorporationDecimals := 2
|
||
183 | else // % |
||
184 | IncorporationDecimals := 3;
|
||
185 | IncorporationFormat := DecimalFormat(IncorporationDecimals); |
||
186 | end;
|
||
187 | |||
188 | function TFormOptions.DecimalFormat(Decimals: Integer): String; |
||
189 | var
|
||
190 | i: Integer; |
||
191 | s: String;
|
||
192 | begin
|
||
193 | s := '#,##0';
|
||
194 | if Decimals > 0 |
||
195 | then
|
||
196 | begin
|
||
197 | s := s + '.';
|
||
198 | for i := 1 to Decimals do |
||
199 | s := s + '0';
|
||
200 | end;
|
||
201 | Result := s; |
||
202 | end;
|
||
203 | |||
204 | procedure TFormOptions.FormCreate(Sender: TObject);
|
||
205 | begin
|
||
206 | if Screen.Fonts.IndexOf('Arial Unicode MS') <> -1 |
||
207 | then
|
||
208 | Font.Name := 'Arial Unicode MS';
|
||
209 | // PanelButtons.Font.Size := PanelButtons.Font.Size + 2;
|
||
210 | PanelButtons.Font.Style := [fsBold]; |
||
211 | TranslateComponent(Self); |
||
212 | // Charger la configuration
|
||
213 | Reg := TRegistry.Create; |
||
214 | Reg.RootKey := HKEY_CURRENT_USER; |
||
215 | if Reg.OpenKeyReadOnly('\Software\EvaPig2020') |
||
216 | then
|
||
217 | begin
|
||
218 | if Reg.ValueExists('GeneralExpression') |
||
219 | then
|
||
220 | Expression := Reg.ReadInteger('GeneralExpression')
|
||
221 | else
|
||
222 | Expression := 0;
|
||
223 | if Reg.ValueExists('ProximalAnalysis') |
||
224 | then
|
||
225 | Proximal := Reg.ReadInteger('ProximalAnalysis')
|
||
226 | else
|
||
227 | Proximal := 0;
|
||
228 | if Reg.ValueExists('EnergyValues') |
||
229 | then
|
||
230 | Energy := Reg.ReadInteger('EnergyValues')
|
||
231 | else
|
||
232 | Energy := 0;
|
||
233 | if Reg.ValueExists('AminoAcids') |
||
234 | then
|
||
235 | AA := Reg.ReadInteger('AminoAcids')
|
||
236 | else
|
||
237 | AA := 0;
|
||
238 | if Reg.ValueExists('Minerals') |
||
239 | then
|
||
240 | Minerals := Reg.ReadInteger('Minerals')
|
||
241 | else
|
||
242 | Minerals := 0;
|
||
243 | if Reg.ValueExists('IncorporationLevel') |
||
244 | then
|
||
245 | Incorporation := Reg.ReadInteger('IncorporationLevel')
|
||
246 | else
|
||
247 | Incorporation := 0;
|
||
248 | if Reg.ValueExists('Language') |
||
249 | then
|
||
250 | CurrentLanguage := Reg.ReadString('Language')
|
||
251 | else
|
||
252 | CurrentLanguage := DefaultInstance.GetCurrentLanguage; |
||
253 | {
|
||
254 | if Reg.ValueExists('Left')
|
||
255 | then
|
||
256 | MainLeft := Reg.ReadInteger('Left')
|
||
257 | else
|
||
258 | MainLeft := 0;
|
||
259 | if Reg.ValueExists('Top')
|
||
260 | then
|
||
261 | MainTop := Reg.ReadInteger('Top')
|
||
262 | else
|
||
263 | MainTop := 0;
|
||
264 | if Reg.ValueExists('Width')
|
||
265 | then
|
||
266 | MainWidth := Reg.ReadInteger('Width')
|
||
267 | else
|
||
268 | MainWidth := 960;
|
||
269 | if Reg.ValueExists('Height')
|
||
270 | then
|
||
271 | MainHeight := Reg.ReadInteger('Height')
|
||
272 | else
|
||
273 | MainHeight := 720;
|
||
274 | }
|
||
275 | Reg.CloseKey; |
||
276 | end
|
||
277 | else
|
||
278 | begin
|
||
279 | Expression := 0;
|
||
280 | Proximal := 0;
|
||
281 | Energy := 0;
|
||
282 | AA := 0;
|
||
283 | Minerals := 0;
|
||
284 | Incorporation := 0;
|
||
285 | CurrentLanguage := DefaultInstance.GetCurrentLanguage; |
||
286 | {
|
||
287 | MainLeft := 0;
|
||
288 | MainTop := 0;
|
||
289 | MainWidth := 960;
|
||
290 | MainHeight := 720;
|
||
291 | }
|
||
292 | end;
|
||
293 | AjustProximal; |
||
294 | AjustEnergy; |
||
295 | AjustAA; |
||
296 | AjustMinerals; |
||
297 | AjustIncorporation; |
||
298 | end;
|
||
299 | |||
300 | procedure TFormOptions.FormDestroy(Sender: TObject);
|
||
301 | begin
|
||
302 | Reg.Free; |
||
303 | end;
|
||
304 | |||
305 | procedure TFormOptions.FormShow(Sender: TObject);
|
||
306 | begin
|
||
307 | ComboBoxExpression.ItemIndex := Expression; |
||
308 | ComboBoxProximal.ItemIndex := Proximal; |
||
309 | ComboBoxEnergy.ItemIndex := Energy; |
||
310 | ComboBoxAA.ItemIndex := AA; |
||
311 | ComboBoxMinerals.ItemIndex := Minerals; |
||
312 | ComboBoxIncorporation.ItemIndex := Incorporation; |
||
313 | end;
|
||
314 | |||
315 | end. |