@@ -160,27 +160,15 @@ interface
160
160
property ItemCount: Integer read GetItemCount;
161
161
end ;
162
162
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
-
172
163
type
173
164
174
- { TODO -cSettings: Investigate why ssApplication section no longer used.
175
- Update below and in docs once found out. }
176
165
// / <summary>
177
166
// / <para>Enumeration of recognised sections within persistent storage.
178
167
// / </para>
179
168
// / <para>-ssFindText - info about last text search</para>
180
169
// / <para>-ssFindCompiler - info about last compiler search</para>
181
170
// / <para>-ssFindXRefs - info about last XRef search</para>
182
171
// / <para>-ssCompilerInfo - info about each supported compiler</para>
183
- // / <para>-ssApplication - info about the application</para>
184
172
// / <para>-ssPreferences - info about program preferences</para>
185
173
// / <para>-ssUserInfo - info about user</para>
186
174
// / <para>-ssUnits - list of default units</para>
@@ -193,7 +181,7 @@ interface
193
181
// / <para>-ssUpdateChecks - info about update checks</para>
194
182
// / </summary>
195
183
TSettingsSectionId = (
196
- ssFindText, ssFindCompiler, ssFindXRefs, ssCompilerInfo, ssApplication,
184
+ ssFindText, ssFindCompiler, ssFindXRefs, ssCompilerInfo,
197
185
ssPreferences, ssUserInfo, ssUnits, ssDuplicateSnippet,
198
186
ssFavourites, ssWindowState, ssDatabase
199
187
);
@@ -241,42 +229,32 @@ implementation
241
229
242
230
uses
243
231
// Delphi
244
- Classes, IniFiles, IOUtils,
232
+ Classes,
233
+ IniFiles,
234
+ IOUtils,
245
235
// Project
246
- UAppInfo, UEncryptor, UExceptions, UHexUtils, UIOUtils, UStrUtils;
236
+ UAppInfo,
237
+ UEncryptor,
238
+ UHexUtils,
239
+ UIOUtils,
240
+ UStrUtils;
247
241
248
242
249
243
var
250
244
// Private global variable: stores reference to settings singleton object
251
245
pvtSettings: ISettings = nil ;
252
246
253
-
254
247
type
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>
270
250
// / <remarks>Implements core ini file functionality.</remarks>
271
- TIniSettingsBase = class (TSettingsBase )
251
+ TIniSettingsBase = class (TInterfacedObject )
272
252
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>
277
255
// / <remarks>The caller is responsible for freeing the returned instance.
278
256
// / </remarks>
279
- function CreateIniFile ( const Storage: TSettingsStorageId) : TIniFile;
257
+ function CreateIniFile : TIniFile;
280
258
public
281
259
// / <summary>Constructs new object instance.</summary>
282
260
constructor Create;
@@ -348,8 +326,6 @@ TIniSettingsSection = class(TIniSettingsBase, ISettingsSection)
348
326
var
349
327
// / <summary>Name of section.</summary>
350
328
fSectionName: string;
351
- // / <summary>Id of storage to be used.</summary>
352
- fStorage: TSettingsStorageId;
353
329
// / <summary>Stores section's data as name=value pairs.</summary>
354
330
fValues: TStringList;
355
331
@@ -374,10 +350,7 @@ TIniSettingsSection = class(TIniSettingsBase, ISettingsSection)
374
350
// / <summary>Construct a new object instance that encapsulates an empty
375
351
// / section.</summary>
376
352
// / <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);
381
354
382
355
// / <summary>Destroys object instance.</summary>
383
356
destructor Destroy; override;
@@ -541,30 +514,6 @@ function Settings: ISettings;
541
514
Result := pvtSettings;
542
515
end ;
543
516
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
-
568
517
{ TIniSettingsBase }
569
518
570
519
constructor TIniSettingsBase.Create;
@@ -575,40 +524,23 @@ constructor TIniSettingsBase.Create;
575
524
TDirectory.CreateDirectory(TAppInfo.CommonAppDir);
576
525
end ;
577
526
578
- function TIniSettingsBase.CreateIniFile (
579
- const Storage: TSettingsStorageId): TIniFile;
527
+ function TIniSettingsBase.CreateIniFile : TIniFile;
580
528
var
581
529
FileName: string; // name if ini file
582
530
begin
583
- FileName := StorageName(Storage) ;
531
+ FileName := TAppInfo.UserConfigFileName ;
584
532
if not TFile.Exists(FileName, False) then
585
533
// create empty Unicode text file with BOM to force Win API to write Unicode
586
534
TFileIO.WriteAllText(FileName, ' ' , TEncoding.Unicode, True);
587
535
Result := TIniFile.Create(FileName);
588
536
end ;
589
537
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
-
603
538
{ TIniSettings }
604
539
605
540
function TIniSettings.CreateSection (const SectionID: TSettingsSectionId;
606
541
const SubSection: string): ISettingsSection;
607
542
begin
608
- Result := TIniSettingsSection.Create(
609
- SectionName(SectionID, SubSection),
610
- SectionStorage(SectionID)
611
- );
543
+ Result := TIniSettingsSection.Create(SectionName(SectionID, SubSection));
612
544
end ;
613
545
614
546
function TIniSettings.EmptySection (const Section: TSettingsSectionId;
@@ -633,7 +565,6 @@ function TIniSettings.SectionName(const Id: TSettingsSectionId;
633
565
' FindCompiler' , // ssFindCompiler
634
566
' FindXRefs' , // ssFindXRefs
635
567
' Cmp' , // ssCompilerInfo
636
- ' Application' , // ssApplication
637
568
' Prefs' , // ssPreferences
638
569
' UserInfo' , // ssUserInfo
639
570
' UnitList' , // ssUnits
@@ -655,13 +586,11 @@ procedure TIniSettingsSection.ClearItems;
655
586
fValues.Clear;
656
587
end ;
657
588
658
- constructor TIniSettingsSection.Create(const Section: string;
659
- const Storage: TSettingsStorageId);
589
+ constructor TIniSettingsSection.Create(const Section: string);
660
590
begin
661
591
inherited Create;
662
592
fValues := TStringList.Create;
663
593
fSectionName := Section;
664
- fStorage := Storage;
665
594
end ;
666
595
667
596
procedure TIniSettingsSection.DeleteItem (const Name : string);
@@ -759,7 +688,7 @@ function TIniSettingsSection.ItemExists(const Name: string): Boolean;
759
688
procedure TIniSettingsSection.Load ;
760
689
begin
761
690
// Read all values from section in app's ini file to data item storage
762
- with CreateIniFile(fStorage) do
691
+ with CreateIniFile do
763
692
try
764
693
ReadSectionValues(fSectionName, fValues);
765
694
finally
@@ -788,7 +717,7 @@ procedure TIniSettingsSection.Save;
788
717
Idx: Integer; // loops thru all data items in section
789
718
begin
790
719
// Open application's ini file
791
- with CreateIniFile(fStorage) do
720
+ with CreateIniFile do
792
721
try
793
722
// Delete any existing section with same name
794
723
EraseSection(fSectionName);
0 commit comments