Changeset 75 for trunk/Packages/Common/RegistryEx.pas
- Timestamp:
- Jun 4, 2024, 12:22:49 AM (5 months ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/RegistryEx.pas
r74 r75 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; … … 43 41 end; 44 42 45 function RegContext(RootKey: HKEY; Key: string): TRegistryContext; 43 const 44 RegistryRootHKEY: array[TRegistryRoot] of HKEY = (HKEY_CLASSES_ROOT, 45 HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE, HKEY_USERS, HKEY_PERFORMANCE_DATA, 46 HKEY_CURRENT_CONFIG, HKEY_DYN_DATA); 46 47 47 48 48 49 implementation 49 50 function RegContext(RootKey: HKEY; Key: string): TRegistryContext;51 begin52 Result.RootKey := RootKey;53 Result.Key := Key;54 end;55 50 56 51 { TRegistryContext } … … 59 54 begin 60 55 Result := (A.Key = B.Key) and (A.RootKey = B.RootKey); 56 end; 57 58 class function TRegistryContext.Create(RootKey: TRegistryRoot; Key: string): TRegistryContext; 59 begin 60 Result.RootKey := RegistryRootHKEY[RootKey]; 61 Result.Key := Key; 62 end; 63 64 class function TRegistryContext.Create(RootKey: HKEY; Key: string): TRegistryContext; 65 begin 66 Result.RootKey := RootKey; 67 Result.Key := Key; 61 68 end; 62 69 … … 79 86 else begin 80 87 WriteString(Name, DefaultValue); 88 Result := DefaultValue; 89 end; 90 end; 91 92 function TRegistryEx.ReadCharWithDefault(const Name: string; DefaultValue: Char 93 ): Char; 94 begin 95 if ValueExists(Name) then Result := ReadChar(Name) 96 else begin 97 WriteChar(Name, DefaultValue); 81 98 Result := DefaultValue; 82 99 end; … … 113 130 function TRegistryEx.OpenKey(const Key: string; CanCreate: Boolean): Boolean; 114 131 begin 115 {$IFDEF Linux}116 CloseKey;132 {$IFDEF UNIX} 133 //CloseKey; 117 134 {$ENDIF} 118 135 Result := inherited OpenKey(Key, CanCreate); … … 121 138 function TRegistryEx.GetCurrentContext: TRegistryContext; 122 139 begin 123 Result.Key := CurrentPath;140 Result.Key := String(CurrentPath); 124 141 Result.RootKey := RootKey; 125 142 end; … … 129 146 RootKey := AValue.RootKey; 130 147 OpenKey(AValue.Key, True); 148 end; 149 150 function TRegistryEx.ReadChar(const Name: string): Char; 151 var 152 S: string; 153 begin 154 S := ReadString(Name); 155 if Length(S) > 0 then Result := S[1] 156 else Result := #0; 157 end; 158 159 procedure TRegistryEx.WriteChar(const Name: string; Value: Char); 160 begin 161 WriteString(Name, Value); 131 162 end; 132 163
Note:
See TracChangeset
for help on using the changeset viewer.