Changeset 25 for trunk/Packages/Common/URegistry.pas
- Timestamp:
- Sep 10, 2022, 6:54:43 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/URegistry.pas
r20 r25 1 1 unit URegistry; 2 3 {$MODE Delphi}4 2 5 3 interface … … 17 15 RootKey: HKEY; 18 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; 19 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;22 20 end; 23 21 … … 29 27 procedure SetCurrentContext(AValue: TRegistryContext); 30 28 public 29 function ReadChar(const Name: string): Char; 30 procedure WriteChar(const Name: string; Value: Char); 31 31 function ReadBoolWithDefault(const Name: string; 32 32 DefaultValue: Boolean): Boolean; 33 33 function ReadIntegerWithDefault(const Name: string; DefaultValue: Integer): Integer; 34 34 function ReadStringWithDefault(const Name: string; DefaultValue: string): string; 35 function ReadCharWithDefault(const Name: string; DefaultValue: Char): Char; 35 36 function ReadFloatWithDefault(const Name: string; 36 37 DefaultValue: Double): Double; … … 41 42 function GetValue(const Name: string; const DefaultValue: Boolean): Boolean; overload; 42 43 function GetValue(const Name: string; const DefaultValue: Double): Double; overload; 44 function GetValue(const Name: string; const DefaultValue: Char): Char; overload; 43 45 procedure SetValue(const Name: string; const Value: Integer); overload; 44 46 procedure SetValue(const Name: string; const Value: string); overload; 45 47 procedure SetValue(const Name: string; const Value: Boolean); overload; 46 48 procedure SetValue(const Name: string; const Value: Double); overload; 49 procedure SetValue(const Name: string; const Value: Char); overload; 47 50 property CurrentContext: TRegistryContext read GetCurrentContext write SetCurrentContext; 48 51 end; … … 53 56 HKEY_CURRENT_CONFIG, HKEY_DYN_DATA); 54 57 58 55 59 implementation 56 60 57 58 61 { TRegistryContext } 59 62 … … 63 66 end; 64 67 65 function TRegistryContext.Create(RootKey: TRegistryRoot; Key: string): TRegistryContext;68 class function TRegistryContext.Create(RootKey: TRegistryRoot; Key: string): TRegistryContext; 66 69 begin 67 70 Result.RootKey := RegistryRootHKEY[RootKey]; … … 69 72 end; 70 73 71 function TRegistryContext.Create(RootKey: HKEY; Key: string): TRegistryContext;74 class function TRegistryContext.Create(RootKey: HKEY; Key: string): TRegistryContext; 72 75 begin 73 76 Result.RootKey := RootKey; … … 97 100 end; 98 101 102 function TRegistryEx.ReadCharWithDefault(const Name: string; DefaultValue: Char 103 ): Char; 104 begin 105 if ValueExists(Name) then Result := ReadChar(Name) 106 else begin 107 WriteChar(Name, DefaultValue); 108 Result := DefaultValue; 109 end; 110 end; 111 99 112 function TRegistryEx.ReadFloatWithDefault(const Name: string; 100 113 DefaultValue: Double): Double; … … 131 144 end; 132 145 146 function TRegistryEx.GetValue(const Name: string; const DefaultValue: Char 147 ): Char; 148 begin 149 Result := ReadCharWithDefault(Name, DefaultValue); 150 end; 151 133 152 procedure TRegistryEx.SetValue(const Name: string; const Value: Integer); 134 153 begin … … 149 168 begin 150 169 WriteFloat(Name, Value); 170 end; 171 172 procedure TRegistryEx.SetValue(const Name: string; const Value: Char); 173 begin 174 WriteChar(Name, Value); 151 175 end; 152 176 … … 171 195 function TRegistryEx.OpenKey(const Key: string; CanCreate: Boolean): Boolean; 172 196 begin 173 {$IFDEF Linux}174 CloseKey;197 {$IFDEF UNIX} 198 //CloseKey; 175 199 {$ENDIF} 176 200 Result := inherited OpenKey(Key, CanCreate); … … 179 203 function TRegistryEx.GetCurrentContext: TRegistryContext; 180 204 begin 181 Result.Key := CurrentPath;205 Result.Key := String(CurrentPath); 182 206 Result.RootKey := RootKey; 183 207 end; … … 189 213 end; 190 214 215 function TRegistryEx.ReadChar(const Name: string): Char; 216 var 217 S: string; 218 begin 219 S := ReadString(Name); 220 if Length(S) > 0 then Result := S[1] 221 else Result := #0; 222 end; 223 224 procedure TRegistryEx.WriteChar(const Name: string; Value: Char); 225 begin 226 WriteString(Name, Value); 227 end; 228 191 229 function TRegistryEx.ReadBoolWithDefault(const Name: string; 192 230 DefaultValue: Boolean): Boolean;
Note:
See TracChangeset
for help on using the changeset viewer.