@@ -160,27 +160,15 @@ interface
160160 property ItemCount: Integer read GetItemCount;
161161 end ;
162162
163- type
164- // / <summary>
165- // / <para>Enumeration of the different storage locations that can store
166- // / settings.</para>
167- // / <para>- ssUser - Storage for per-user settings.</para>
168- // / <para>- ssCommon - Storage for common (application-wde) settings.</para>
169- // / </summary>
170- TSettingsStorageId = (ssUser, ssCommon);
171-
172163type
173164
174- { TODO -cSettings: Investigate why ssApplication section no longer used.
175- Update below and in docs once found out. }
176165 // / <summary>
177166 // / <para>Enumeration of recognised sections within persistent storage.
178167 // / </para>
179168 // / <para>-ssFindText - info about last text search</para>
180169 // / <para>-ssFindCompiler - info about last compiler search</para>
181170 // / <para>-ssFindXRefs - info about last XRef search</para>
182171 // / <para>-ssCompilerInfo - info about each supported compiler</para>
183- // / <para>-ssApplication - info about the application</para>
184172 // / <para>-ssPreferences - info about program preferences</para>
185173 // / <para>-ssUserInfo - info about user</para>
186174 // / <para>-ssUnits - list of default units</para>
@@ -193,7 +181,7 @@ interface
193181 // / <para>-ssUpdateChecks - info about update checks</para>
194182 // / </summary>
195183 TSettingsSectionId = (
196- ssFindText, ssFindCompiler, ssFindXRefs, ssCompilerInfo, ssApplication,
184+ ssFindText, ssFindCompiler, ssFindXRefs, ssCompilerInfo,
197185 ssPreferences, ssUserInfo, ssUnits, ssDuplicateSnippet,
198186 ssFavourites, ssWindowState, ssDatabase
199187 );
@@ -241,42 +229,32 @@ implementation
241229
242230uses
243231 // Delphi
244- Classes, IniFiles, IOUtils,
232+ Classes,
233+ IniFiles,
234+ IOUtils,
245235 // Project
246- UAppInfo, UEncryptor, UExceptions, UHexUtils, UIOUtils, UStrUtils;
236+ UAppInfo,
237+ UEncryptor,
238+ UHexUtils,
239+ UIOUtils,
240+ UStrUtils;
247241
248242
249243var
250244 // Private global variable: stores reference to settings singleton object
251245 pvtSettings: ISettings = nil ;
252246
253-
254247type
255- // / <summary>Base class for all settings classes, regardless of storage
256- // / medium used.</summary>
257- TSettingsBase = class (TInterfacedObject)
258- strict protected
259- // / <summary>Determines and returns identifier of the storage entity on
260- // / which a section is stored.</summary>
261- // / <param name="Section">TSettingsSectionId [in] Id of section.</param>
262- // / <returns>Id of required storage.</returns>
263- function SectionStorage (const Section: TSettingsSectionId):
264- TSettingsStorageId;
265- end ;
266-
267- type
268- // / <summary>Base class for all settings classes that use ini files for
269- // / persisent storage.</summary>
248+ // / <summary>Base class for all settings classes that use setting ini file
249+ // / for persisent storage.</summary>
270250 // / <remarks>Implements core ini file functionality.</remarks>
271- TIniSettingsBase = class (TSettingsBase )
251+ TIniSettingsBase = class (TInterfacedObject )
272252 strict protected
273- // / <summary>Maps the given storage id to the storage file name.</summary>
274- function StorageName (const Storage: TSettingsStorageId): string;
275- // / <summary>Creates and returns a TIniFile instance onto the ini file
276- // / for the given storage id.</summary>
253+ // / <summary>Creates and returns a TIniFile instance onto the settings ini
254+ // / file.</summary>
277255 // / <remarks>The caller is responsible for freeing the returned instance.
278256 // / </remarks>
279- function CreateIniFile ( const Storage: TSettingsStorageId) : TIniFile;
257+ function CreateIniFile : TIniFile;
280258 public
281259 // / <summary>Constructs new object instance.</summary>
282260 constructor Create;
@@ -348,8 +326,6 @@ TIniSettingsSection = class(TIniSettingsBase, ISettingsSection)
348326 var
349327 // / <summary>Name of section.</summary>
350328 fSectionName: string;
351- // / <summary>Id of storage to be used.</summary>
352- fStorage: TSettingsStorageId;
353329 // / <summary>Stores section's data as name=value pairs.</summary>
354330 fValues: TStringList;
355331
@@ -374,10 +350,7 @@ TIniSettingsSection = class(TIniSettingsBase, ISettingsSection)
374350 // / <summary>Construct a new object instance that encapsulates an empty
375351 // / section.</summary>
376352 // / <param name="Section">string [in] Name of section in ini file.</param>
377- // / <param name="Storage">TSettingsStorageId [in] Identifies the storage
378- // / (i.e. ini file) to be used.</param>
379- constructor Create(const Section: string;
380- const Storage: TSettingsStorageId);
353+ constructor Create(const Section: string);
381354
382355 // / <summary>Destroys object instance.</summary>
383356 destructor Destroy; override;
@@ -541,30 +514,6 @@ function Settings: ISettings;
541514 Result := pvtSettings;
542515end ;
543516
544- { TSettingsBase }
545-
546- function TSettingsBase.SectionStorage (
547- const Section: TSettingsSectionId): TSettingsStorageId;
548- const
549- // Map of known sections onto storage that contains them
550- cSectionStorageMap: array [TSettingsSectionId] of TSettingsStorageId = (
551- ssUser, // ssFindText
552- ssUser, // ssFindCompiler
553- ssUser, // ssFindXRefs
554- ssUser, // ssCompilerInfo
555- ssCommon, // ssApplication
556- ssUser, // ssPreferences
557- ssUser, // ssUserInfo
558- ssUser, // ssUnits
559- ssUser, // ssDuplicateSnippet
560- ssUser, // ssFavourites
561- ssUser, // ssWindowState
562- ssUser // ssDatabase
563- );
564- begin
565- Result := cSectionStorageMap[Section];
566- end ;
567-
568517{ TIniSettingsBase }
569518
570519constructor TIniSettingsBase.Create;
@@ -575,40 +524,23 @@ constructor TIniSettingsBase.Create;
575524 TDirectory.CreateDirectory(TAppInfo.CommonAppDir);
576525end ;
577526
578- function TIniSettingsBase.CreateIniFile (
579- const Storage: TSettingsStorageId): TIniFile;
527+ function TIniSettingsBase.CreateIniFile : TIniFile;
580528var
581529 FileName: string; // name if ini file
582530begin
583- FileName := StorageName(Storage) ;
531+ FileName := TAppInfo.UserConfigFileName ;
584532 if not TFile.Exists(FileName, False) then
585533 // create empty Unicode text file with BOM to force Win API to write Unicode
586534 TFileIO.WriteAllText(FileName, ' ' , TEncoding.Unicode, True);
587535 Result := TIniFile.Create(FileName);
588536end ;
589537
590- function TIniSettingsBase.StorageName (
591- const Storage: TSettingsStorageId): string;
592- begin
593- case Storage of
594- ssUser:
595- Result := TAppInfo.UserConfigFileName;
596- ssCommon:
597- Result := TAppInfo.AppConfigFileName;
598- else
599- raise EBug.Create(ClassName + ' .StorageName: unknown storage type' );
600- end ;
601- end ;
602-
603538{ TIniSettings }
604539
605540function TIniSettings.CreateSection (const SectionID: TSettingsSectionId;
606541 const SubSection: string): ISettingsSection;
607542begin
608- Result := TIniSettingsSection.Create(
609- SectionName(SectionID, SubSection),
610- SectionStorage(SectionID)
611- );
543+ Result := TIniSettingsSection.Create(SectionName(SectionID, SubSection));
612544end ;
613545
614546function TIniSettings.EmptySection (const Section: TSettingsSectionId;
@@ -633,7 +565,6 @@ function TIniSettings.SectionName(const Id: TSettingsSectionId;
633565 ' FindCompiler' , // ssFindCompiler
634566 ' FindXRefs' , // ssFindXRefs
635567 ' Cmp' , // ssCompilerInfo
636- ' Application' , // ssApplication
637568 ' Prefs' , // ssPreferences
638569 ' UserInfo' , // ssUserInfo
639570 ' UnitList' , // ssUnits
@@ -655,13 +586,11 @@ procedure TIniSettingsSection.ClearItems;
655586 fValues.Clear;
656587end ;
657588
658- constructor TIniSettingsSection.Create(const Section: string;
659- const Storage: TSettingsStorageId);
589+ constructor TIniSettingsSection.Create(const Section: string);
660590begin
661591 inherited Create;
662592 fValues := TStringList.Create;
663593 fSectionName := Section;
664- fStorage := Storage;
665594end ;
666595
667596procedure TIniSettingsSection.DeleteItem (const Name : string);
@@ -759,7 +688,7 @@ function TIniSettingsSection.ItemExists(const Name: string): Boolean;
759688procedure TIniSettingsSection.Load ;
760689begin
761690 // Read all values from section in app's ini file to data item storage
762- with CreateIniFile(fStorage) do
691+ with CreateIniFile do
763692 try
764693 ReadSectionValues(fSectionName, fValues);
765694 finally
@@ -788,7 +717,7 @@ procedure TIniSettingsSection.Save;
788717 Idx: Integer; // loops thru all data items in section
789718begin
790719 // Open application's ini file
791- with CreateIniFile(fStorage) do
720+ with CreateIniFile do
792721 try
793722 // Delete any existing section with same name
794723 EraseSection(fSectionName);
0 commit comments