Changeset 38 for trunk/Components/Common/URegistry.pas
- Timestamp:
- Apr 18, 2019, 3:34:38 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Components/Common/URegistry.pas
r34 r38 9 9 10 10 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)); 11 TRegistryRoot = (rrKeyClassesRoot, rrKeyCurrentUser, rrKeyLocalMachine, 12 rrKeyUsers, rrKeyPerformanceData, rrKeyCurrentConfig, rrKeyDynData); 18 13 19 14 { TRegistryContext } … … 23 18 Key: string; 24 19 class operator Equal(A, B: TRegistryContext): Boolean; 20 function Create(RootKey: TRegistryRoot; Key: string): TRegistryContext; overload; 21 function Create(RootKey: HKEY; Key: string): TRegistryContext; overload; 25 22 end; 26 23 … … 32 29 procedure SetCurrentContext(AValue: TRegistryContext); 33 30 public 31 function ReadChar(const Name: string): Char; 32 procedure WriteChar(const Name: string; Value: Char); 34 33 function ReadBoolWithDefault(const Name: string; 35 34 DefaultValue: Boolean): Boolean; 36 35 function ReadIntegerWithDefault(const Name: string; DefaultValue: Integer): Integer; 37 36 function ReadStringWithDefault(const Name: string; DefaultValue: string): string; 37 function ReadCharWithDefault(const Name: string; DefaultValue: Char): Char; 38 38 function ReadFloatWithDefault(const Name: string; 39 39 DefaultValue: Double): Double; … … 43 43 end; 44 44 45 function RegContext(RootKey: HKEY; Key: string): TRegistryContext; 46 45 const 46 RegistryRootHKEY: array[TRegistryRoot] of HKEY = (HKEY_CLASSES_ROOT, 47 HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE, HKEY_USERS, HKEY_PERFORMANCE_DATA, 48 HKEY_CURRENT_CONFIG, HKEY_DYN_DATA); 47 49 48 50 implementation 49 51 50 function RegContext(RootKey: HKEY; Key: string): TRegistryContext;51 begin52 Result.RootKey := RootKey;53 Result.Key := Key;54 end;55 52 56 53 { TRegistryContext } … … 59 56 begin 60 57 Result := (A.Key = B.Key) and (A.RootKey = B.RootKey); 58 end; 59 60 function TRegistryContext.Create(RootKey: TRegistryRoot; Key: string): TRegistryContext; 61 begin 62 Result.RootKey := RegistryRootHKEY[RootKey]; 63 Result.Key := Key; 64 end; 65 66 function TRegistryContext.Create(RootKey: HKEY; Key: string): TRegistryContext; 67 begin 68 Result.RootKey := RootKey; 69 Result.Key := Key; 61 70 end; 62 71 … … 79 88 else begin 80 89 WriteString(Name, DefaultValue); 90 Result := DefaultValue; 91 end; 92 end; 93 94 function TRegistryEx.ReadCharWithDefault(const Name: string; DefaultValue: Char 95 ): Char; 96 begin 97 if ValueExists(Name) then Result := ReadChar(Name) 98 else begin 99 WriteChar(Name, DefaultValue); 81 100 Result := DefaultValue; 82 101 end; … … 131 150 end; 132 151 152 function TRegistryEx.ReadChar(const Name: string): Char; 153 var 154 S: string; 155 begin 156 S := ReadString(Name); 157 if Length(S) > 0 then Result := S[1] 158 else Result := #0; 159 end; 160 161 procedure TRegistryEx.WriteChar(const Name: string; Value: Char); 162 begin 163 WriteString(Name, Value); 164 end; 165 133 166 function TRegistryEx.ReadBoolWithDefault(const Name: string; 134 167 DefaultValue: Boolean): Boolean;
Note:
See TracChangeset
for help on using the changeset viewer.