|
@@ -81,6 +81,7 @@ type
|
|
|
FName: string;
|
|
|
FKeyList: TIniFileKeyList;
|
|
|
public
|
|
|
+ Function Empty : Boolean;
|
|
|
constructor Create(AName: string);
|
|
|
destructor Destroy; override;
|
|
|
property Name: string read FName;
|
|
@@ -143,6 +144,8 @@ type
|
|
|
FCacheUpdates: Boolean;
|
|
|
FDirty : Boolean;
|
|
|
procedure FillSectionList(AStrings: TStrings);
|
|
|
+ Procedure DeleteSection(ASection : TIniFileSection);
|
|
|
+ Procedure MaybeDeleteSection(ASection : TIniFileSection);
|
|
|
protected
|
|
|
procedure MaybeUpdateFile;
|
|
|
property Dirty : Boolean Read FDirty;
|
|
@@ -255,6 +258,22 @@ begin
|
|
|
inherited Clear;
|
|
|
end;
|
|
|
|
|
|
+Function TIniFileSection.Empty : Boolean;
|
|
|
+
|
|
|
+Var
|
|
|
+ I : Integer;
|
|
|
+
|
|
|
+begin
|
|
|
+ Result:=True;
|
|
|
+ I:=0;
|
|
|
+ While Result and (I<KeyList.Count) do
|
|
|
+ begin
|
|
|
+ result:=IsComment(KeyList[i].Ident);
|
|
|
+ Inc(i);
|
|
|
+ end;
|
|
|
+end;
|
|
|
+
|
|
|
+
|
|
|
{ TIniFileSection }
|
|
|
|
|
|
constructor TIniFileSection.Create(AName: string);
|
|
@@ -332,8 +351,13 @@ begin
|
|
|
end;
|
|
|
|
|
|
function TCustomIniFile.SectionExists(const Section: string): Boolean;
|
|
|
+
|
|
|
+Var
|
|
|
+ S : TIniFileSection;
|
|
|
+
|
|
|
begin
|
|
|
- Result := (FSectionList.SectionByName(Section,CaseSensitive) <> nil);
|
|
|
+ S:=FSectionList.SectionByName(Section,CaseSensitive);
|
|
|
+ Result:=Assigned(S) and Not S.Empty;
|
|
|
end;
|
|
|
|
|
|
function TCustomIniFile.ReadInteger(const Section, Ident: string; Default: Longint): Longint;
|
|
@@ -765,6 +789,20 @@ begin
|
|
|
end;
|
|
|
end;
|
|
|
|
|
|
+procedure TIniFile.DeleteSection(ASection : TIniFileSection);
|
|
|
+
|
|
|
+begin
|
|
|
+ FSectionList.Delete(FSectionList.IndexOf(ASection));
|
|
|
+ ASection.Free;
|
|
|
+end;
|
|
|
+
|
|
|
+Procedure TIniFile.MaybeDeleteSection(ASection : TIniFileSection);
|
|
|
+
|
|
|
+begin
|
|
|
+ If Asection.Empty then
|
|
|
+ DeleteSection(ASection);
|
|
|
+end;
|
|
|
+
|
|
|
procedure TIniFile.EraseSection(const Section: string);
|
|
|
var
|
|
|
oSection: TIniFileSection;
|
|
@@ -773,8 +811,7 @@ begin
|
|
|
if oSection <> nil then begin
|
|
|
{ It is needed so UpdateFile doesn't find a defunct section }
|
|
|
{ and cause the program to crash }
|
|
|
- FSectionList.Delete(FSectionList.IndexOf(oSection));
|
|
|
- oSection.Free;
|
|
|
+ DeleteSection(OSection);
|
|
|
MaybeUpdateFile;
|
|
|
end;
|
|
|
end;
|
|
@@ -784,15 +821,18 @@ var
|
|
|
oSection: TIniFileSection;
|
|
|
oKey: TIniFileKey;
|
|
|
begin
|
|
|
- oSection := FSectionList.SectionByName(Section,CaseSensitive);
|
|
|
- if oSection <> nil then begin
|
|
|
- oKey := oSection.KeyList.KeyByName(Ident,CaseSensitive);
|
|
|
- if oKey <> nil then begin
|
|
|
- oSection.KeyList.Delete(oSection.KeyList.IndexOf(oKey));
|
|
|
- oKey.Free;
|
|
|
- MaybeUpdateFile;
|
|
|
- end;
|
|
|
- end;
|
|
|
+ oSection := FSectionList.SectionByName(Section,CaseSensitive);
|
|
|
+ if oSection <> nil then
|
|
|
+ begin
|
|
|
+ oKey := oSection.KeyList.KeyByName(Ident,CaseSensitive);
|
|
|
+ if oKey <> nil then
|
|
|
+ begin
|
|
|
+ oSection.KeyList.Delete(oSection.KeyList.IndexOf(oKey));
|
|
|
+ oKey.Free;
|
|
|
+ MaybeDeleteSection(oSection);
|
|
|
+ MaybeUpdateFile;
|
|
|
+ end;
|
|
|
+ end;
|
|
|
end;
|
|
|
|
|
|
procedure TIniFile.UpdateFile;
|