Skip to content

Commit 9ed3f8d

Browse files
committed
Refactor to generalise TCompilerSettings
TCompilerSettings was generalised to make it easier to add new properties.
1 parent 60f68dc commit 9ed3f8d

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

Src/Compilers.USettings.pas

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
interface
1515

1616
uses
17+
// Delphi
18+
SysUtils,
19+
// Project
1720
UBaseObjects,
1821
USettings;
1922

@@ -24,7 +27,11 @@ TCompilerSettings = class(TNoConstructObject)
2427
const
2528
AllCompilersConfigSection = ssCompilers;
2629
PermitStartupDetectionKey = 'PermitStartupDetection';
30+
ListFPCAtTopKey = 'Lists:FPCAtTop';
31+
ListDelphiOldestFirstKey = 'Lists:DelphiOldestFirst';
2732
class function ReadStorage: ISettingsSection;
33+
class procedure DoSaveProperty(const WriteProp: TProc<ISettingsSection>);
34+
class procedure SaveProperty(const Key: string; const Value: Boolean);
2835
class function GetPermitStartupDetection: Boolean; static;
2936
class procedure SetPermitStartupDetection(const Value: Boolean); static;
3037
public
@@ -37,6 +44,16 @@ implementation
3744

3845
{ TCompilerSettings }
3946

47+
class procedure TCompilerSettings.DoSaveProperty(
48+
const WriteProp: TProc<ISettingsSection>);
49+
var
50+
Stg: ISettingsSection;
51+
begin
52+
Stg := ReadStorage;
53+
WriteProp(Stg);
54+
Stg.Save;
55+
end;
56+
4057
class function TCompilerSettings.GetPermitStartupDetection: Boolean;
4158
begin
4259
Result := ReadStorage.GetBoolean(PermitStartupDetectionKey, True);
@@ -47,14 +64,21 @@ class function TCompilerSettings.ReadStorage: ISettingsSection;
4764
Result := Settings.ReadSection(AllCompilersConfigSection);
4865
end;
4966

67+
class procedure TCompilerSettings.SaveProperty(const Key: string;
68+
const Value: Boolean);
69+
begin
70+
DoSaveProperty(
71+
procedure(Stg: ISettingsSection)
72+
begin
73+
Stg.SetBoolean(Key, Value)
74+
end
75+
);
76+
end;
77+
5078
class procedure TCompilerSettings.SetPermitStartupDetection(
5179
const Value: Boolean);
52-
var
53-
Stg: ISettingsSection;
5480
begin
55-
Stg := ReadStorage;
56-
Stg.SetBoolean(PermitStartupDetectionKey, Value);
57-
Stg.Save;
81+
SaveProperty(PermitStartupDetectionKey, Value);
5882
end;
5983

6084
end.

0 commit comments

Comments
 (0)