-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinifilesex.pas
116 lines (88 loc) · 3.19 KB
/
inifilesex.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
unit IniFilesEx;
{$mode objfpc}{$H+}
interface
uses
IniFiles,classes;
Type
{ TIniFileEx }
TIniFileEx=class (TIniFile)
public
isDirty:Boolean;
procedure markDirty;
function ReadInteger (const Section, Ident:String; const Default,min,max: Longint): Longint; virtual;overload;
procedure UpdateFile; override;
procedure UpdateFileIfDirty;
//handle dirtynes :)
procedure WriteString(const Section, Ident, Value: String);override;
procedure WriteInteger(const Section, Ident: string; Value: Longint); override;
procedure WriteBool(const Section, Ident: string; Value: Boolean); override;
procedure WriteDate(const Section, Ident: string; Value: TDateTime); override;
procedure WriteDateTime(const Section, Ident: string; Value: TDateTime); override;
procedure WriteFloat(const Section, Ident: string; Value: Double); override;
procedure WriteTime(const Section, Ident: string; Value: TDateTime); override;
procedure WriteBinaryStream(const Section, Name: string; Value: TStream); override;
procedure EraseSection(const Section: string); override;
procedure DeleteKey(const Section, Ident: String); override;
end;
implementation
uses sysutils;
{ TIniFileEx }
procedure TIniFileEx.markDirty;
begin
isDirty:=true;
end;
function TIniFileEx.ReadInteger(const Section, Ident: String; const Default, min, max: Longint): Longint;
begin
Result:=inherited ReadInteger(Section,Ident,Default);
if (Result<min) or(Result>max) then Result:=Default;
end;
procedure TIniFileEx.UpdateFile;
begin
inherited UpdateFile;
isDirty:=false;
end;
procedure TIniFileEx.UpdateFileIfDirty;
begin
if (isDirty) then UpdateFile;
end;
procedure TIniFileEx.WriteString(const Section, Ident, Value: String);
begin
inherited WriteString(Section, Ident, Value); isDirty:=true;
end;
procedure TIniFileEx.WriteInteger(const Section, Ident: string; Value: Longint);
begin
inherited WriteInteger(Section, Ident, Value); isDirty:=true;
end;
procedure TIniFileEx.WriteBool(const Section, Ident: string; Value: Boolean);
begin
inherited WriteBool(Section, Ident, Value); isDirty:=true;
end;
procedure TIniFileEx.WriteDate(const Section, Ident: string; Value: TDateTime);
begin
inherited WriteDate(Section, Ident, Value); isDirty:=true;
end;
procedure TIniFileEx.WriteDateTime(const Section, Ident: string; Value: TDateTime);
begin
inherited WriteDateTime(Section, Ident, Value); isDirty:=true;
end;
procedure TIniFileEx.WriteFloat(const Section, Ident: string; Value: Double);
begin
inherited WriteFloat(Section, Ident, Value); isDirty:=true;
end;
procedure TIniFileEx.WriteTime(const Section, Ident: string; Value: TDateTime);
begin
inherited WriteTime(Section, Ident, Value); isDirty:=true;
end;
procedure TIniFileEx.WriteBinaryStream(const Section, Name: string; Value: TStream);
begin
inherited WriteBinaryStream(Section, Name, Value); isDirty:=true;
end;
procedure TIniFileEx.EraseSection(const Section: string);
begin
inherited EraseSection(Section); isDirty:=true;
end;
procedure TIniFileEx.DeleteKey(const Section, Ident: String);
begin
inherited DeleteKey(Section, Ident); isDirty:=true;
end;
end.