-
Notifications
You must be signed in to change notification settings - Fork 1
/
RegSettings.pas
137 lines (115 loc) · 3.08 KB
/
RegSettings.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
unit RegSettings;
interface
type
TRegSettings = class (TObject)
private
FSongLayoutColNumbers: boolean;
FPatternRowHex: boolean;
bDirty: boolean;
procedure SetPatternRowHex(const Value: boolean);
procedure SetSongLayoutColNumbers(const Value: boolean);
public
property ShowLayoutColNumbers: boolean read FSongLayoutColNumbers write SetSongLayoutColNumbers;
property PatternRowNumbersHex: boolean read FPatternRowHex write SetPatternRowHex;
property Dirty: boolean read bDirty;
procedure SaveSettings();
procedure LoadSettings();
constructor Create();
end;
implementation
{ TRegSettings }
uses Registry, Windows, SysUtils;
function RegGetInt(Reg: TRegistry; sKey: string; iDefault: integer): integer;
begin
try
Result := Reg.ReadInteger(sKey);
except
on ERegistryException do Result := iDefault;
end;
end;
function RegGetDateTime(Reg: TRegistry; sKey: string; dtDefault: TDateTime): TDateTime;
begin
try
Result := Reg.ReadDateTime(sKey);
except
on ERegistryException do Result := dtDefault;
end;
end;
function RegGetBool(Reg: TRegistry; sKey: string; bDefault: boolean): boolean;
begin
try
Result := Reg.ReadBool(sKey);
except
on ERegistryException do Result := bDefault;
end;
end;
function RegGetString(Reg: TRegistry; sKey: string; sDefault: string): string;
begin
try
Result := Reg.ReadString(sKey);
except
on ERegistryException do Result := sDefault;
end;
if (Result = '') then Result := sDefault;
end;
constructor TRegSettings.Create;
begin
inherited;
LoadSettings();
end;
procedure TRegSettings.LoadSettings;
var
Reg: TRegistry;
begin
try
Reg := TRegistry.Create(KEY_READ or KEY_WRITE);
try
Reg.RootKey := HKEY_CURRENT_USER;
if Reg.OpenKey('\Software\Grok\Beepola\Options',true) then
begin
FSongLayoutColNumbers := RegGetBool(Reg,'ShowLayoutColNumbers',false);
FPatternRowHex := RegGetBool(Reg,'PatternRowHex',false);
end;
finally
Reg.CloseKey;
end;
except
on ERegistryException do;
end;
FreeAndNil(Reg);
bDirty := false;
end;
procedure TRegSettings.SaveSettings;
var
Reg: TRegistry;
begin
if not bDirty then exit;
try
Reg := TRegistry.Create(KEY_READ or KEY_WRITE);
try
Reg.RootKey := HKEY_CURRENT_USER;
if Reg.OpenKey('\Software\Grok\Beepola\Options',true) then
begin
Reg.WriteBool('ShowLayoutColNumbers',FSongLayoutColNumbers);
Reg.WriteBool('PatternRowHex',FPatternRowHex);
end;
finally
Reg.CloseKey;
end;
except
on ERegistryException do;
end;
FreeAndNil(Reg);
bDirty := false;
end;
procedure TRegSettings.SetPatternRowHex(const Value: boolean);
begin
if (Value <> FPatternRowHex) then bDirty := true;
FPatternRowHex := Value;
end;
procedure TRegSettings.SetSongLayoutColNumbers(const Value: boolean);
begin
if (Value <> FSongLayoutColNumbers) then bDirty := true;
FSongLayoutColNumbers := Value;
end;
end.