|
@@ -97,12 +97,13 @@ override;
|
|
end;
|
|
end;
|
|
|
|
|
|
TCustomIniFile = class
|
|
TCustomIniFile = class
|
|
|
|
+ Private
|
|
FFileName: string;
|
|
FFileName: string;
|
|
FSectionList: TIniFileSectionList;
|
|
FSectionList: TIniFileSectionList;
|
|
FEscapeLineFeeds: boolean;
|
|
FEscapeLineFeeds: boolean;
|
|
FCaseSensitive : Boolean;
|
|
FCaseSensitive : Boolean;
|
|
public
|
|
public
|
|
- constructor Create(const AFileName: string);
|
|
|
|
|
|
+ constructor Create(const AFileName: string); virtual;
|
|
destructor Destroy; override;
|
|
destructor Destroy; override;
|
|
function SectionExists(const Section: string): Boolean; virtual;
|
|
function SectionExists(const Section: string): Boolean; virtual;
|
|
function ReadString(const Section, Ident, Default: string): string; virtual; abstract;
|
|
function ReadString(const Section, Ident, Default: string): string; virtual; abstract;
|
|
@@ -131,15 +132,21 @@ override;
|
|
Property CaseSensitive : Boolean Read FCaseSensitive Write FCaseSensitive;
|
|
Property CaseSensitive : Boolean Read FCaseSensitive Write FCaseSensitive;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+ { TIniFile }
|
|
|
|
+
|
|
TIniFile = class(TCustomIniFile)
|
|
TIniFile = class(TCustomIniFile)
|
|
|
|
+ Private
|
|
FStream: TStream;
|
|
FStream: TStream;
|
|
- private
|
|
|
|
|
|
+ FCacheUpdates: Boolean;
|
|
|
|
+ FDirty : Boolean;
|
|
procedure FillSectionList(AStrings: TStrings);
|
|
procedure FillSectionList(AStrings: TStrings);
|
|
protected
|
|
protected
|
|
- procedure WriteStringInMemory(const Section, Ident, Value: String);
|
|
|
|
|
|
+ procedure MaybeUpdateFile;
|
|
|
|
+ property Dirty : Boolean Read FDirty;
|
|
public
|
|
public
|
|
- constructor Create(const AFileName: string);
|
|
|
|
|
|
+ constructor Create(const AFileName: string); override;
|
|
constructor Create(AStream: TStream);
|
|
constructor Create(AStream: TStream);
|
|
|
|
+ destructor Destroy; override;
|
|
function ReadString(const Section, Ident, Default: string): string; override;
|
|
function ReadString(const Section, Ident, Default: string): string; override;
|
|
procedure WriteString(const Section, Ident, Value: String); override;
|
|
procedure WriteString(const Section, Ident, Value: String); override;
|
|
procedure ReadSection(const Section: string; Strings: TStrings); override;
|
|
procedure ReadSection(const Section: string; Strings: TStrings); override;
|
|
@@ -150,15 +157,16 @@ override;
|
|
procedure DeleteKey(const Section, Ident: String); override;
|
|
procedure DeleteKey(const Section, Ident: String); override;
|
|
procedure UpdateFile; override;
|
|
procedure UpdateFile; override;
|
|
property Stream: TStream read FStream;
|
|
property Stream: TStream read FStream;
|
|
|
|
+ property CacheUpdates : Boolean Read FCacheUpdates Write FCacheUpdates;
|
|
end;
|
|
end;
|
|
|
|
|
|
TMemIniFile = class(TIniFile)
|
|
TMemIniFile = class(TIniFile)
|
|
public
|
|
public
|
|
|
|
+ constructor Create(const AFileName: string); override;
|
|
procedure Clear;
|
|
procedure Clear;
|
|
procedure GetStrings(List: TStrings);
|
|
procedure GetStrings(List: TStrings);
|
|
procedure Rename(const AFileName: string; Reload: Boolean);
|
|
procedure Rename(const AFileName: string; Reload: Boolean);
|
|
procedure SetStrings(List: TStrings);
|
|
procedure SetStrings(List: TStrings);
|
|
- procedure WriteString(const Section, Ident, Value: String); override;
|
|
|
|
end;
|
|
end;
|
|
|
|
|
|
implementation
|
|
implementation
|
|
@@ -486,6 +494,13 @@ begin
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+destructor TIniFile.destroy;
|
|
|
|
+begin
|
|
|
|
+ If FDirty and FCacheUpdates then
|
|
|
|
+ UpdateFile;
|
|
|
|
+ inherited destroy;
|
|
|
|
+end;
|
|
|
|
+
|
|
procedure TIniFile.FillSectionList(AStrings: TStrings);
|
|
procedure TIniFile.FillSectionList(AStrings: TStrings);
|
|
var
|
|
var
|
|
i,j: integer;
|
|
i,j: integer;
|
|
@@ -585,7 +600,7 @@ begin
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
-procedure TIniFile.WriteStringInMemory(const Section, Ident, Value: String);
|
|
|
|
|
|
+procedure TIniFile.WriteString(const Section, Ident, Value: String);
|
|
var
|
|
var
|
|
oSection: TIniFileSection;
|
|
oSection: TIniFileSection;
|
|
oKey: TIniFileKey;
|
|
oKey: TIniFileKey;
|
|
@@ -613,14 +628,7 @@ begin
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
-end;
|
|
|
|
-
|
|
|
|
-procedure TIniFile.WriteString(const Section, Ident, Value: String);
|
|
|
|
-begin
|
|
|
|
- if (Section > '') and (Ident > '') then begin
|
|
|
|
- WriteStringInMemory(Section, Ident, Value);
|
|
|
|
- UpdateFile;
|
|
|
|
- end;
|
|
|
|
|
|
+ MaybeUpdateFile;
|
|
end;
|
|
end;
|
|
|
|
|
|
procedure TIniFile.ReadSection(const Section: string; Strings: TStrings);
|
|
procedure TIniFile.ReadSection(const Section: string; Strings: TStrings);
|
|
@@ -709,7 +717,7 @@ begin
|
|
{ and cause the program to crash }
|
|
{ and cause the program to crash }
|
|
FSectionList.Delete(FSectionList.IndexOf(oSection));
|
|
FSectionList.Delete(FSectionList.IndexOf(oSection));
|
|
oSection.Free;
|
|
oSection.Free;
|
|
- UpdateFile;
|
|
|
|
|
|
+ MaybeUpdateFile;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
@@ -724,7 +732,7 @@ begin
|
|
if oKey <> nil then begin
|
|
if oKey <> nil then begin
|
|
oSection.KeyList.Delete(oSection.KeyList.IndexOf(oKey));
|
|
oSection.KeyList.Delete(oSection.KeyList.IndexOf(oKey));
|
|
oKey.Free;
|
|
oKey.Free;
|
|
- UpdateFile;
|
|
|
|
|
|
+ MaybeUpdateFile;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
@@ -764,8 +772,23 @@ begin
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+procedure TIniFile.MaybeUpdateFile;
|
|
|
|
+begin
|
|
|
|
+ If FCacheUpdates then
|
|
|
|
+ FDirty:=True
|
|
|
|
+ else
|
|
|
|
+ UpdateFile;
|
|
|
|
+end;
|
|
|
|
+
|
|
{ TMemIniFile }
|
|
{ TMemIniFile }
|
|
|
|
|
|
|
|
+constructor TMemIniFile.Create(const AFileName: string);
|
|
|
|
+
|
|
|
|
+begin
|
|
|
|
+ Inherited;
|
|
|
|
+ FCacheUpdates:=True;
|
|
|
|
+end;
|
|
|
|
+
|
|
procedure TMemIniFile.Clear;
|
|
procedure TMemIniFile.Clear;
|
|
begin
|
|
begin
|
|
FSectionList.Clear;
|
|
FSectionList.Clear;
|
|
@@ -822,11 +845,4 @@ begin
|
|
FillSectionList(List);
|
|
FillSectionList(List);
|
|
end;
|
|
end;
|
|
|
|
|
|
-procedure TMemIniFile.WriteString(const Section, Ident, Value: String);
|
|
|
|
-begin
|
|
|
|
- if (Section > '') and (Ident > '') then begin
|
|
|
|
- WriteStringInMemory(Section, Ident, Value);
|
|
|
|
- end;
|
|
|
|
-end;
|
|
|
|
-
|
|
|
|
end.
|
|
end.
|