Changeset 21 for trunk/Packages/Common/RegistryEx.pas
- Timestamp:
- Apr 3, 2025, 10:49:00 PM (13 days ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/RegistryEx.pas
r20 r21 1 unit URegistry; 2 3 {$MODE Delphi} 1 unit RegistryEx; 4 2 5 3 interface … … 9 7 10 8 type 11 TRegistryRoot = (rrKeyClassesRoot = HKEY($80000000), 12 rrKeyCurrentUser = HKEY($80000001), 13 rrKeyLocalMachine = HKEY($80000002), 14 rrKeyUsers = HKEY($80000003), 15 rrKeyPerformanceData = HKEY($80000004), 16 rrKeyCurrentConfig = HKEY($80000005), 17 rrKeyDynData = HKEY($80000006)); 9 TRegistryRoot = (rrKeyClassesRoot, rrKeyCurrentUser, rrKeyLocalMachine, 10 rrKeyUsers, rrKeyPerformanceData, rrKeyCurrentConfig, rrKeyDynData); 18 11 19 12 { TRegistryContext } … … 22 15 RootKey: HKEY; 23 16 Key: string; 17 class function Create(RootKey: TRegistryRoot; Key: string): TRegistryContext; static; overload; 18 class function Create(RootKey: HKEY; Key: string): TRegistryContext; static; overload; 24 19 class operator Equal(A, B: TRegistryContext): Boolean; 25 20 end; … … 32 27 procedure SetCurrentContext(AValue: TRegistryContext); 33 28 public 29 function ReadChar(const Name: string): Char; 30 procedure WriteChar(const Name: string; Value: Char); 34 31 function ReadBoolWithDefault(const Name: string; 35 32 DefaultValue: Boolean): Boolean; 36 33 function ReadIntegerWithDefault(const Name: string; DefaultValue: Integer): Integer; 37 34 function ReadStringWithDefault(const Name: string; DefaultValue: string): string; 35 function ReadCharWithDefault(const Name: string; DefaultValue: Char): Char; 38 36 function ReadFloatWithDefault(const Name: string; 39 37 DefaultValue: Double): Double; 38 function ReadDateTimeWithDefault(const Name: string; DefaultValue: TDateTime): TDateTime; 40 39 function DeleteKeyRecursive(const Key: string): Boolean; 41 40 function OpenKey(const Key: string; CanCreate: Boolean): Boolean; … … 43 42 end; 44 43 45 function RegContext(RootKey: HKEY; Key: string): TRegistryContext; 44 const 45 RegistryRootHKEY: array[TRegistryRoot] of HKEY = (HKEY_CLASSES_ROOT, 46 HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE, HKEY_USERS, HKEY_PERFORMANCE_DATA, 47 HKEY_CURRENT_CONFIG, HKEY_DYN_DATA); 46 48 47 49 48 50 implementation 49 50 function RegContext(RootKey: HKEY; Key: string): TRegistryContext;51 begin52 Result.RootKey := RootKey;53 Result.Key := Key;54 end;55 51 56 52 { TRegistryContext } … … 59 55 begin 60 56 Result := (A.Key = B.Key) and (A.RootKey = B.RootKey); 57 end; 58 59 class function TRegistryContext.Create(RootKey: TRegistryRoot; Key: string): TRegistryContext; 60 begin 61 Result.RootKey := RegistryRootHKEY[RootKey]; 62 Result.Key := Key; 63 end; 64 65 class function TRegistryContext.Create(RootKey: HKEY; Key: string): TRegistryContext; 66 begin 67 Result.RootKey := RootKey; 68 Result.Key := Key; 61 69 end; 62 70 … … 83 91 end; 84 92 93 function TRegistryEx.ReadCharWithDefault(const Name: string; DefaultValue: Char 94 ): Char; 95 begin 96 if ValueExists(Name) then Result := ReadChar(Name) 97 else begin 98 WriteChar(Name, DefaultValue); 99 Result := DefaultValue; 100 end; 101 end; 102 85 103 function TRegistryEx.ReadFloatWithDefault(const Name: string; 86 104 DefaultValue: Double): Double; … … 89 107 else begin 90 108 WriteFloat(Name, DefaultValue); 109 Result := DefaultValue; 110 end; 111 end; 112 113 function TRegistryEx.ReadDateTimeWithDefault(const Name: string; 114 DefaultValue: TDateTime): TDateTime; 115 begin 116 if ValueExists(Name) then Result := ReadDateTime(Name) 117 else begin 118 WriteDateTime(Name, DefaultValue); 91 119 Result := DefaultValue; 92 120 end; … … 113 141 function TRegistryEx.OpenKey(const Key: string; CanCreate: Boolean): Boolean; 114 142 begin 115 {$IFDEF Linux}116 CloseKey;143 {$IFDEF UNIX} 144 //CloseKey; 117 145 {$ENDIF} 118 Result := inherited OpenKey(Key, CanCreate);146 Result := inherited; 119 147 end; 120 148 121 149 function TRegistryEx.GetCurrentContext: TRegistryContext; 122 150 begin 123 Result.Key := CurrentPath;151 Result.Key := String(CurrentPath); 124 152 Result.RootKey := RootKey; 125 153 end; … … 129 157 RootKey := AValue.RootKey; 130 158 OpenKey(AValue.Key, True); 159 end; 160 161 function TRegistryEx.ReadChar(const Name: string): Char; 162 var 163 S: string; 164 begin 165 S := ReadString(Name); 166 if Length(S) > 0 then Result := S[1] 167 else Result := #0; 168 end; 169 170 procedure TRegistryEx.WriteChar(const Name: string; Value: Char); 171 begin 172 WriteString(Name, Value); 131 173 end; 132 174
Note:
See TracChangeset
for help on using the changeset viewer.