-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfigEditorsBase.pas
More file actions
108 lines (85 loc) · 2.68 KB
/
ConfigEditorsBase.pas
File metadata and controls
108 lines (85 loc) · 2.68 KB
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
unit ConfigEditorsBase;
interface
uses
System.SysUtils, System.Classes, System.JSON, JSONHelpers;
type
// 閰嶇疆缂栬緫鍣ㄥ熀绫绘帴鍙?
IConfigEditor = interface
['{B2D4F9E1-6A9D-4F98-8C10-E4B4E96F5D32}']
// 鑾峰彇缂栬緫鍣ㄧ被鍨?
function GetEditorType: TConfigType;
// 鍔犺浇閰嶇疆瀵硅薄
procedure Load(const Config: TJSONObject);
// 淇濆瓨鍒伴厤缃璞?
function Save: TJSONObject;
// 淇敼鐘舵€?
function GetModified: Boolean;
procedure SetModified(const Value: Boolean);
// 閫氱煡浜嬩欢
function GetOnModified: TNotifyEvent;
procedure SetOnModified(const Value: TNotifyEvent);
// 灞炴€?
property EditorType: TConfigType read GetEditorType;
property Modified: Boolean read GetModified write SetModified;
property OnModified: TNotifyEvent read GetOnModified write SetOnModified;
end;
// 閰嶇疆缂栬緫鍣ㄥ熀绫?
TConfigEditorBase = class(TInterfacedObject, IConfigEditor)
private
FModified: Boolean;
FOnModified: TNotifyEvent;
FConfigType: TConfigType;
function GetModified: Boolean;
procedure SetModified(const Value: Boolean);
function GetOnModified: TNotifyEvent;
procedure SetOnModified(const Value: TNotifyEvent);
protected
// 閰嶇疆鍙樻洿閫氱煡
procedure DoModified; virtual;
public
constructor Create; virtual;
// IConfigEditor鎺ュ彛瀹炵幇
function GetEditorType: TConfigType; virtual; abstract;
procedure Load(const Config: TJSONObject); virtual; abstract;
function Save: TJSONObject; virtual; abstract;
// 灞炴€?
property Modified: Boolean read GetModified write SetModified;
property OnModified: TNotifyEvent read GetOnModified write SetOnModified;
property ConfigType: TConfigType read FConfigType write FConfigType;
end;
// 缂栬緫鍣ㄥ垱寤哄嚱鏁扮被鍨?
TConfigEditorCreateFunc = function: IConfigEditor;
implementation
{ TConfigEditorBase }
constructor TConfigEditorBase.Create;
begin
inherited Create;
FModified := False;
end;
procedure TConfigEditorBase.DoModified;
begin
if Assigned(FOnModified) then
FOnModified(Self);
end;
function TConfigEditorBase.GetModified: Boolean;
begin
Result := FModified;
end;
function TConfigEditorBase.GetOnModified: TNotifyEvent;
begin
Result := FOnModified;
end;
procedure TConfigEditorBase.SetModified(const Value: Boolean);
begin
if FModified <> Value then
begin
FModified := Value;
if FModified then
DoModified;
end;
end;
procedure TConfigEditorBase.SetOnModified(const Value: TNotifyEvent);
begin
FOnModified := Value;
end;
end.