-
Notifications
You must be signed in to change notification settings - Fork 33
/
HGM.Common.Settings.pas
810 lines (734 loc) · 23.6 KB
/
HGM.Common.Settings.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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
unit HGM.Common.Settings;
interface
uses
Winapi.Windows, System.SysUtils, System.Variants, System.Classes, IniFiles, Registry, System.Generics.Collections,
{$IFDEF NEEDFMX}
FMX.Forms,
{$ELSE}
Vcl.Forms, Vcl.Samples.Spin, Vcl.Grids, Vcl.ValEdit, Vcl.ExtCtrls, Vcl.ComCtrls, Vcl.StdCtrls,
{$ENDIF NEEDFMX}
System.UITypes;
type
TRegRoot = (rrHKLM, rrHKCU);
TWindowParamSave = set of (wpsAll, wpsCoord, wpsSize, wpsState);
TSettings = class
private
function ReadInt(Section, Param: string; var Value: Integer; Default: Integer = 0): Boolean; virtual; abstract;
function ReadStr(Section, Param: string; var Value: string; Default: string = ''): Boolean; virtual; abstract;
function ReadBool(Section, Param: string; var Value: Boolean; Default: Boolean = False): Boolean; virtual; abstract;
function ReadDate(Section, Param: string; var Value: TDateTime; Default: TDateTime = 0): Boolean; virtual; abstract;
function ReadFloat(Section, Param: string; var Value: Extended; Default: Extended = 0.0): Boolean; virtual; abstract;
function WriteInt(Section, Param: string; Value: Integer): Boolean; virtual; abstract;
function WriteStr(Section, Param: string; Value: string): Boolean; virtual; abstract;
function WriteBool(Section, Param: string; Value: Boolean): Boolean; virtual; abstract;
function WriteDate(Section, Param: string; Value: TDateTime): Boolean; virtual; abstract;
function WriteFloat(Section, Param: string; Value: Extended): Boolean; virtual; abstract;
function FValueExists(Section, Param: string): Boolean; virtual; abstract;
function FGetSections(Section: string; List: TStringList): Boolean; virtual; abstract;
public
//function Get<T: TEnum>(Section, Param: string; Default: T): T;
function GetInt(Section, Param: string; Default: Integer = 0): Integer;
function GetStr(Section, Param: string; Default: string = ''): string;
function GetBool(Section, Param: string; Default: Boolean = False): Boolean;
function GetDate(Section, Param: string; Default: TDateTime = 0): TDateTime;
function GetFloat(Section, Param: string; Default: Extended = 0.0): Extended;
function SetInt(Section, Param: string; Value: Integer): Boolean;
function SetStr(Section, Param: string; Value: string): Boolean;
function SetBool(Section, Param: string; Value: Boolean): Boolean;
function SetDate(Section, Param: string; Value: TDateTime): Boolean;
function SetFloat(Section, Param: string; Value: Extended): Boolean;
{$IFDEF NEEDFMX}
function GetParamWindow(Section: string; AWindow: FMX.Forms.TForm; LoadItems: TWindowParamSave): Boolean; overload;
function SetParamWindow(Section: string; AWindow: FMX.Forms.TForm; SaveItems: TWindowParamSave): Boolean; overload;
{$ELSE}
function GetParam(Section: string; AControl: TEdit; Default: string = ''): Boolean; overload;
function GetParam(Section: string; AControl: TLabel; Default: string = ''): Boolean; overload;
function GetParam(Section: string; AControl: TSpinEdit; Default: Integer = 0): Boolean; overload;
function GetParam(Section: string; AControl: TCustomComboBox; Default: Integer = 0): Boolean; overload;
function GetParam(Section: string; AControl: TCheckBox; Default: Boolean = False): Boolean; overload;
function GetParam(Section: string; AControl: TPageControl; Default: Integer = 0): Boolean; overload;
function SetParam(Section: string; AControl: TEdit): Boolean; overload;
function SetParam(Section: string; AControl: TLabel): Boolean; overload;
function SetParam(Section: string; AControl: TSpinEdit): Boolean; overload;
function SetParam(Section: string; AControl: TCustomComboBox): Boolean; overload;
function SetParam(Section: string; AControl: TCheckBox): Boolean; overload;
function SetParam(Section: string; AControl: TPageControl): Boolean; overload;
function GetParamWindow(Section: string; AWindow: Vcl.Forms.TForm; LoadItems: TWindowParamSave): Boolean; overload;
function SetParamWindow(Section: string; AWindow: Vcl.Forms.TForm; SaveItems: TWindowParamSave): Boolean; overload;
{$ENDIF NEEDFMX}
function ValueExists(Section, Param: string): Boolean;
function GetSections(Section: string; List: TStringList): Boolean;
end;
TSettingsReg = class(TSettings)
private
FRoot: TRegRoot;
FPath: string;
function CreateReg(Access: Cardinal; Root: HKEY): TRegistry;
function ReadInt(Section, Param: string; var Value: Integer; Default: Integer = 0): Boolean; override;
function ReadStr(Section, Param: string; var Value: string; Default: string = ''): Boolean; override;
function ReadBool(Section, Param: string; var Value: Boolean; Default: Boolean = False): Boolean; override;
function ReadDate(Section, Param: string; var Value: TDateTime; Default: TDateTime = 0): Boolean; override;
function ReadFloat(Section, Param: string; var Value: Extended; Default: Extended = 0.0): Boolean; override;
function WriteInt(Section, Param: string; Value: Integer): Boolean; override;
function WriteStr(Section, Param: string; Value: string): Boolean; override;
function WriteBool(Section, Param: string; Value: Boolean): Boolean; override;
function WriteDate(Section, Param: string; Value: TDateTime): Boolean; override;
function WriteFloat(Section, Param: string; Value: Extended): Boolean; override;
function FValueExists(Section, Param: string): Boolean; override;
function FGetSections(Section: string; List: TStringList): Boolean; override;
public
constructor Create(ARoot: TRegRoot; APath: string);
property Root: TRegRoot read FRoot write FRoot;
property Path: string read FPath write FPath;
end;
TSettingsIni = class(TSettings)
private
FFileName: string;
function CreateIni: TIniFile;
function ReadInt(Section, Param: string; var Value: Integer; Default: Integer = 0): Boolean; override;
function ReadStr(Section, Param: string; var Value: string; Default: string = ''): Boolean; override;
function ReadBool(Section, Param: string; var Value: Boolean; Default: Boolean = False): Boolean; override;
function ReadDate(Section, Param: string; var Value: TDateTime; Default: TDateTime = 0): Boolean; override;
function ReadFloat(Section, Param: string; var Value: Extended; Default: Extended = 0.0): Boolean; override;
function WriteInt(Section, Param: string; Value: Integer): Boolean; override;
function WriteStr(Section, Param: string; Value: string): Boolean; override;
function WriteBool(Section, Param: string; Value: Boolean): Boolean; override;
function WriteDate(Section, Param: string; Value: TDateTime): Boolean; override;
function WriteFloat(Section, Param: string; Value: Extended): Boolean; override;
function FValueExists(Section, Param: string): Boolean; override;
function FGetSections(Section: string; List: TStringList): Boolean; override;
public
constructor Create(AFileName: string);
constructor CreateDefault(const AppName: string);
property FileName: string read FFileName write FFileName;
end;
function RegRootToHKEY(Value: TRegRoot): HKEY;
implementation
uses
System.IOUtils;
function RegRootToHKEY(Value: TRegRoot): HKEY;
begin
case Value of
rrHKLM:
Result := HKEY_LOCAL_MACHINE;
rrHKCU:
Result := HKEY_CURRENT_USER;
else
Result := HKEY_CURRENT_USER;
end;
end;
{ TSettingsReg }
constructor TSettingsReg.Create(ARoot: TRegRoot; APath: string);
begin
inherited Create;
FRoot := ARoot;
FPath := APath;
end;
function TSettingsReg.CreateReg(Access: Cardinal; Root: HKEY): TRegistry;
begin
Result := TRegistry.Create;
Result.Access := Access;
Result.RootKey := Root;
end;
function TSettingsReg.FGetSections(Section: string; List: TStringList): Boolean;
begin
with CreateReg(KEY_READ, RegRootToHKEY(FRoot)) do
begin
try
Result := OpenKeyReadOnly(Path + '\' + Section);
if Result then
GetKeyNames(List);
except
Result := False;
end;
Free;
end;
end;
function TSettingsReg.FValueExists(Section, Param: string): Boolean;
begin
with CreateReg(KEY_READ, RegRootToHKEY(FRoot)) do
begin
try
Result := OpenKeyReadOnly(Path + '\' + Section);
if Result then
Result := ValueExists(Param);
except
Result := False;
end;
Free;
end;
end;
function TSettingsReg.ReadBool(Section, Param: string; var Value: Boolean; Default: Boolean): Boolean;
begin
Value := Default;
with CreateReg(KEY_READ, RegRootToHKEY(FRoot)) do
begin
try
Result := OpenKeyReadOnly(Path + '\' + Section);
if Result then
Value := ReadBool(Param);
except
Result := False;
end;
Free;
end;
end;
function TSettingsReg.ReadDate(Section, Param: string; var Value: TDateTime; Default: TDateTime): Boolean;
begin
Value := Default;
with CreateReg(KEY_READ, RegRootToHKEY(FRoot)) do
begin
try
Result := OpenKeyReadOnly(Path + '\' + Section);
if Result then
Value := ReadDateTime(Param);
except
Result := False;
end;
Free;
end;
end;
function TSettingsReg.ReadFloat(Section, Param: string; var Value: Extended; Default: Extended): Boolean;
begin
Value := Default;
with CreateReg(KEY_READ, RegRootToHKEY(FRoot)) do
begin
try
Result := OpenKeyReadOnly(Path + '\' + Section);
if Result then
Value := ReadFloat(Param);
except
Result := False;
end;
Free;
end;
end;
function TSettingsReg.ReadInt(Section, Param: string; var Value: Integer; Default: Integer): Boolean;
begin
Value := Default;
with CreateReg(KEY_READ, RegRootToHKEY(FRoot)) do
begin
try
Result := OpenKeyReadOnly(Path + '\' + Section);
if Result then
Value := ReadInteger(Param);
except
Result := False;
end;
Free;
end;
end;
function TSettingsReg.ReadStr(Section, Param: string; var Value: string; Default: string): Boolean;
begin
Value := Default;
with CreateReg(KEY_READ, RegRootToHKEY(FRoot)) do
begin
try
Result := OpenKeyReadOnly(Path + '\' + Section);
if Result then
Value := ReadString(Param);
except
Result := False;
end;
Free;
end;
end;
function TSettingsReg.WriteBool(Section, Param: string; Value: Boolean): Boolean;
begin
with CreateReg(KEY_WRITE, RegRootToHKEY(FRoot)) do
begin
try
Result := OpenKey(Path + '\' + Section, True);
if Result then
WriteBool(Param, Value);
except
Result := False;
end;
Free;
end;
end;
function TSettingsReg.WriteDate(Section, Param: string; Value: TDateTime): Boolean;
begin
with CreateReg(KEY_WRITE, RegRootToHKEY(FRoot)) do
begin
try
Result := OpenKey(Path + '\' + Section, True);
if Result then
WriteDateTime(Param, Value);
except
Result := False;
end;
Free;
end;
end;
function TSettingsReg.WriteFloat(Section, Param: string; Value: Extended): Boolean;
begin
with CreateReg(KEY_WRITE, RegRootToHKEY(FRoot)) do
begin
try
Result := OpenKey(Path + '\' + Section, True);
if Result then
WriteFloat(Param, Value);
except
Result := False;
end;
Free;
end;
end;
function TSettingsReg.WriteInt(Section, Param: string; Value: Integer): Boolean;
begin
with CreateReg(KEY_WRITE, RegRootToHKEY(FRoot)) do
begin
try
Result := OpenKey(Path + '\' + Section, True);
if Result then
WriteInteger(Param, Value);
except
Result := False;
end;
Free;
end;
end;
function TSettingsReg.WriteStr(Section, Param, Value: string): Boolean;
begin
with CreateReg(KEY_WRITE, RegRootToHKEY(FRoot)) do
begin
try
Result := OpenKey(Path + '\' + Section, True);
if Result then
WriteString(Param, Value);
except
Result := False;
end;
Free;
end;
end;
{ TSettingsIni }
constructor TSettingsIni.Create(AFileName: string);
begin
inherited Create;
FFileName := AFileName;
end;
constructor TSettingsIni.CreateDefault(const AppName: string);
var
Dir: string;
begin
Dir := TPath.Combine(TPath.GetHomePath, AppName);
TDirectory.CreateDirectory(Dir);
Create(TPath.Combine(Dir, 'settings.ini'));
end;
function TSettingsIni.CreateIni: TIniFile;
begin
if not FileExists(FileName) then
FileClose(FileCreate(FileName));
Result := TIniFile.Create(FileName);
end;
function TSettingsIni.FGetSections(Section: string; List: TStringList): Boolean;
begin
with CreateIni do
begin
try
Result := FileExists(FileName);
if Result then
ReadSections(List);
except
Result := False;
end;
Free;
end;
end;
function TSettingsIni.FValueExists(Section, Param: string): Boolean;
begin
with CreateIni do
begin
try
Result := FileExists(FileName);
if Result then
Result := ValueExists(Section, Param);
except
Result := False;
end;
Free;
end;
end;
function TSettingsIni.ReadBool(Section, Param: string; var Value: Boolean; Default: Boolean): Boolean;
begin
Value := Default;
with CreateIni do
begin
try
Result := FileExists(FileName);
if Result then
Value := ReadBool(Section, Param, Default);
except
Result := False;
end;
Free;
end;
end;
function TSettingsIni.ReadDate(Section, Param: string; var Value: TDateTime; Default: TDateTime): Boolean;
begin
Value := Default;
with CreateIni do
begin
try
Result := FileExists(FileName);
if Result then
Value := ReadDateTime(Section, Param, Default);
except
Result := False;
end;
Free;
end;
end;
function TSettingsIni.ReadFloat(Section, Param: string; var Value: Extended; Default: Extended): Boolean;
begin
Value := Default;
with CreateIni do
begin
try
Result := FileExists(FileName);
if Result then
Value := ReadFloat(Section, Param, Default);
except
Result := False;
end;
Free;
end;
end;
function TSettingsIni.ReadInt(Section, Param: string; var Value: Integer; Default: Integer): Boolean;
begin
Value := Default;
with CreateIni do
begin
try
Result := FileExists(FileName);
if Result then
Value := ReadInteger(Section, Param, Default);
except
Result := False;
end;
Free;
end;
end;
function TSettingsIni.ReadStr(Section, Param: string; var Value: string; Default: string): Boolean;
begin
Value := Default;
with CreateIni do
begin
try
Result := FileExists(FileName);
if Result then
Value := ReadString(Section, Param, Default);
except
Result := False;
end;
Free;
end;
end;
function TSettingsIni.WriteBool(Section, Param: string; Value: Boolean): Boolean;
begin
with CreateIni do
begin
try
WriteBool(Section, Param, Value);
Result := True;
except
Result := False;
end;
Free;
end;
end;
function TSettingsIni.WriteDate(Section, Param: string; Value: TDateTime): Boolean;
begin
with CreateIni do
begin
try
WriteDateTime(Section, Param, Value);
Result := True;
except
Result := False;
end;
Free;
end;
end;
function TSettingsIni.WriteFloat(Section, Param: string; Value: Extended): Boolean;
begin
with CreateIni do
begin
try
WriteFloat(Section, Param, Value);
Result := True;
except
Result := False;
end;
Free;
end;
end;
function TSettingsIni.WriteInt(Section, Param: string; Value: Integer): Boolean;
begin
with CreateIni do
begin
try
WriteInteger(Section, Param, Value);
Result := True;
except
Result := False;
end;
Free;
end;
end;
function TSettingsIni.WriteStr(Section, Param, Value: string): Boolean;
begin
with CreateIni do
begin
try
WriteString(Section, Param, Value);
Result := True;
except
Result := False;
end;
Free;
end;
end;
{ TSettings }
{
function TSettings.Get<T>(Section, Param: string; Default: T): T;
var Res: Integer;
It: System.TFloatSpecial;
begin
ReadInt(Section, Param, Res, Ord(T));
Result := T(Res);
end; }
function TSettings.GetBool(Section, Param: string; Default: Boolean): Boolean;
begin
ReadBool(Section, Param, Result, Default);
end;
function TSettings.GetDate(Section, Param: string; Default: TDateTime): TDateTime;
begin
ReadDate(Section, Param, Result, Default);
end;
function TSettings.GetFloat(Section, Param: string; Default: Extended): Extended;
begin
ReadFloat(Section, Param, Result, Default);
end;
function TSettings.GetInt(Section, Param: string; Default: Integer): Integer;
begin
ReadInt(Section, Param, Result, Default);
end;
function TSettings.GetSections(Section: string; List: TStringList): Boolean;
begin
Result := FGetSections(Section, List);
end;
function TSettings.GetStr(Section, Param, Default: string): string;
begin
ReadStr(Section, Param, Result, Default);
end;
function TSettings.SetBool(Section, Param: string; Value: Boolean): Boolean;
begin
Result := WriteBool(Section, Param, Value);
end;
function TSettings.SetDate(Section, Param: string; Value: TDateTime): Boolean;
begin
Result := WriteDate(Section, Param, Value);
end;
function TSettings.SetFloat(Section, Param: string; Value: Extended): Boolean;
begin
Result := WriteFloat(Section, Param, Value);
end;
function TSettings.SetInt(Section, Param: string; Value: Integer): Boolean;
begin
Result := WriteInt(Section, Param, Value);
end;
function TSettings.SetStr(Section, Param, Value: string): Boolean;
begin
Result := WriteStr(Section, Param, Value);
end;
function TSettings.ValueExists(Section, Param: string): Boolean;
begin
Result := FValueExists(Section, Param);
end;
{$IFNDEF NEEDFMX}
function TSettings.GetParam(Section: string; AControl: TEdit; Default: string = ''): Boolean;
var
Str: string;
begin
Result := ReadStr(Section, AControl.Name, Str, Default);
AControl.Text := Str;
end;
function TSettings.SetParam(Section: string; AControl: TEdit): Boolean;
begin
Result := WriteStr(Section, AControl.Name, AControl.Text);
end;
function TSettings.GetParam(Section: string; AControl: TLabel; Default: string): Boolean;
var
Str: string;
begin
Result := ReadStr(Section, AControl.Name, Str, Default);
AControl.Caption := Str;
end;
function TSettings.SetParam(Section: string; AControl: TLabel): Boolean;
begin
Result := WriteStr(Section, AControl.Name, AControl.Caption);
end;
function TSettings.GetParam(Section: string; AControl: TSpinEdit; Default: Integer = 0): Boolean;
var
Value: Integer;
begin
Result := ReadInt(Section, AControl.Name, Value, Default);
AControl.Value := Value;
end;
function TSettings.SetParam(Section: string; AControl: TSpinEdit): Boolean;
begin
Result := WriteInt(Section, AControl.Name, AControl.Value);
end;
function TSettings.GetParam(Section: string; AControl: TCheckBox; Default: Boolean): Boolean;
var
Value: Boolean;
begin
Result := ReadBool(Section, AControl.Name, Value, Default);
AControl.Checked := Value;
end;
function TSettings.GetParam(Section: string; AControl: TCustomComboBox; Default: Integer): Boolean;
var
Value: Integer;
begin
Result := ReadInt(Section, AControl.Name, Value, Default);
AControl.ItemIndex := Value;
end;
function TSettings.SetParam(Section: string; AControl: TCheckBox): Boolean;
begin
Result := WriteBool(Section, AControl.Name, AControl.Checked);
end;
function TSettings.SetParam(Section: string; AControl: TCustomComboBox): Boolean;
begin
Result := WriteInt(Section, AControl.Name, AControl.ItemIndex);
end;
function TSettings.GetParam(Section: string; AControl: TPageControl; Default: Integer): Boolean;
var
Value: Integer;
begin
Result := ReadInt(Section, AControl.Name, Value, Default);
AControl.ActivePageIndex := Value;
end;
function TSettings.SetParam(Section: string; AControl: TPageControl): Boolean;
begin
Result := WriteInt(Section, AControl.Name, AControl.ActivePageIndex);
end;
{$ENDIF}
{$IFDEF NEEDFMX}
function TSettings.GetParamWindow(Section: string; AWindow: FMX.Forms.TForm; LoadItems: TWindowParamSave): Boolean;
var
IValue: Integer;
begin
try
if (wpsCoord in LoadItems) or (wpsAll in LoadItems) then
begin
if ReadInt(Section, AWindow.Name + '.Left', IValue, AWindow.Left) then
AWindow.Left := IValue;
if ReadInt(Section, AWindow.Name + '.Top', IValue, AWindow.Top) then
AWindow.Top := IValue;
end;
if (wpsSize in LoadItems) or (wpsAll in LoadItems) then
begin
if ReadInt(Section, AWindow.Name + '.Width', IValue, AWindow.Width) then
AWindow.Width := IValue;
if ReadInt(Section, AWindow.Name + '.Height', IValue, AWindow.Height) then
AWindow.Height := IValue;
end;
if (wpsState in LoadItems) or (wpsAll in LoadItems) then
begin
if ReadInt(Section, AWindow.Name + '.WindowState', IValue, Ord(AWindow.WindowState)) then
AWindow.WindowState := TWindowState(IValue);
if AWindow.WindowState = TWindowState.wsMinimized then
AWindow.WindowState := TWindowState.wsNormal;
end;
Result := True;
except
Result := False;
end;
end;
function TSettings.SetParamWindow(Section: string; AWindow: FMX.Forms.TForm; SaveItems: TWindowParamSave): Boolean;
begin
try
if (wpsState in SaveItems) or (wpsAll in SaveItems) then
begin
WriteInt(Section, AWindow.Name + '.WindowState', Ord(AWindow.WindowState));
end;
if AWindow.WindowState = TWindowState.wsNormal then
begin
if (wpsCoord in SaveItems) or (wpsAll in SaveItems) then
begin
WriteInt(Section, AWindow.Name + '.Left', AWindow.Left);
WriteInt(Section, AWindow.Name + '.Top', AWindow.Top);
end;
if (wpsSize in SaveItems) or (wpsAll in SaveItems) then
begin
WriteInt(Section, AWindow.Name + '.Width', AWindow.Width);
WriteInt(Section, AWindow.Name + '.Height', AWindow.Height);
end;
end;
Result := True;
except
Result := False;
end;
end;
{$ELSE}
function TSettings.GetParamWindow(Section: string; AWindow: Vcl.Forms.TForm; LoadItems: TWindowParamSave): Boolean;
var
IValue: Integer;
begin
try
if (wpsCoord in LoadItems) or (wpsAll in LoadItems) then
begin
if ReadInt(Section, AWindow.Name + '.Left', IValue, AWindow.Left) then
AWindow.Left := IValue;
if ReadInt(Section, AWindow.Name + '.Top', IValue, AWindow.Top) then
AWindow.Top := IValue;
end;
if (wpsSize in LoadItems) or (wpsAll in LoadItems) then
begin
if ReadInt(Section, AWindow.Name + '.Width', IValue, AWindow.Width) then
AWindow.Width := IValue;
if ReadInt(Section, AWindow.Name + '.Height', IValue, AWindow.Height) then
AWindow.Height := IValue;
end;
if (wpsState in LoadItems) or (wpsAll in LoadItems) then
begin
if ReadInt(Section, AWindow.Name + '.WindowState', IValue, Ord(AWindow.WindowState)) then
AWindow.WindowState := TWindowState(IValue);
if AWindow.WindowState = wsMinimized then
AWindow.WindowState := wsNormal;
end;
Result := True;
except
Result := False;
end;
end;
function TSettings.SetParamWindow(Section: string; AWindow: Vcl.Forms.TForm; SaveItems: TWindowParamSave): Boolean;
begin
try
if (wpsState in SaveItems) or (wpsAll in SaveItems) then
begin
WriteInt(Section, AWindow.Name + '.WindowState', Ord(AWindow.WindowState));
end;
if AWindow.WindowState = wsNormal then
begin
if (wpsCoord in SaveItems) or (wpsAll in SaveItems) then
begin
WriteInt(Section, AWindow.Name + '.Left', AWindow.Left);
WriteInt(Section, AWindow.Name + '.Top', AWindow.Top);
end;
if (wpsSize in SaveItems) or (wpsAll in SaveItems) then
begin
WriteInt(Section, AWindow.Name + '.Width', AWindow.Width);
WriteInt(Section, AWindow.Name + '.Height', AWindow.Height);
end;
end;
Result := True;
except
Result := False;
end;
end;
{$ENDIF NEEDFMX}
end.