From cc9bc424e42131e72f5adcfad4d31caf63cc3c2a Mon Sep 17 00:00:00 2001 From: michael Date: Thu, 17 May 2007 15:53:02 +0000 Subject: [PATCH] * SectionExists now Delphi compatible git-svn-id: trunk@7378 - --- packages/fcl-base/src/inc/inifiles.pp | 64 ++++++++++++++++++++++----- 1 file changed, 52 insertions(+), 12 deletions(-) diff --git a/packages/fcl-base/src/inc/inifiles.pp b/packages/fcl-base/src/inc/inifiles.pp index dda57e9231..12005e4cc6 100644 --- a/packages/fcl-base/src/inc/inifiles.pp +++ b/packages/fcl-base/src/inc/inifiles.pp @@ -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 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;