- Timestamp:
- Jul 25, 2012, 4:09:33 PM (12 years ago)
- Location:
- Registry
- Files:
-
- 9 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
Registry/UGeneralRegistry.pas
r391 r392 25 25 end; 26 26 27 TRegValueType = (vtUnknown, vtInteger, vtString, vtBinary, vtFloat, vtBoolean); 27 TRegValueType = (vtUnknown, vtInteger, vtString, vtBinary, vtFloat, vtBoolean, 28 vtText); 28 29 29 30 TRegValueInfo = record 30 31 ValueType: TRegValueType; 31 32 Size: Integer; 33 end; 34 35 TRegKey = record 36 Root: NativeInt; 37 Path: string; 32 38 end; 33 39 … … 44 50 function KeyExists(const Name: string): Boolean; virtual; abstract; 45 51 function ValueExists(const Name: string): Boolean; virtual; abstract; 52 function GetKeyInfo(var Value: TRegKeyInfo): Boolean; virtual; abstract; 53 function GetValueInfo(const Name: string; var Value: TRegValueInfo): Boolean; virtual; abstract; 54 function GetValueType(const Name: string): TRegValueType; virtual; abstract; 55 function GetValueSize(const Name: string): Integer; virtual; abstract; 46 56 function OpenKey(const Key: string; CreateNew: Boolean): Boolean; virtual; abstract; 47 57 procedure CloseKey; virtual; abstract; … … 90 100 function DeleteValue(const Name: string): Boolean; 91 101 function RenameValue(const OldName, NewName: string): Boolean; 102 function GetKeyInfo(out Value: TRegKeyInfo): Boolean; 103 function GetValueInfo(const Name: string; out Value: TRegValueInfo): Boolean; 104 function GetValueType(const Name: string): TRegValueType; 105 function GetValueSize(const Name: string): Integer; 92 106 function OpenKey(const Key: string; CreateNew: Boolean): Boolean; 93 107 function ReadBool(const Name: string): Boolean; … … 97 111 function ReadString(const Name: string): string; 98 112 function ReadBinaryData(const Name: string; var Buffer; BufSize: Integer): Integer; 113 function ReadBoolDefault(const Name: string; const DefaultValue: Boolean): Boolean; 114 function ReadDateTimeDefault(const Name: string; const DefaultValue: TDateTime): TDateTime; 115 function ReadFloatDefault(const Name: string; const DefaultValue: Double): Double; 116 function ReadIntegerDefault(const Name: string; const DefaultValue: Integer): Integer; 117 function ReadStringDefault(const Name: string; const DefaultValue: string): string; 99 118 procedure WriteBool(const Name: string; Value: Boolean); 100 119 procedure WriteDateTime(const Name: string; Value: TDateTime); … … 144 163 function KeyExists(const Name: string): Boolean; override; 145 164 function ValueExists(const Name: string): Boolean; override; 165 function GetKeyInfo(var Value: TRegKeyInfo): Boolean; override; 166 function GetValueInfo(const Name: string; var Value: TRegValueInfo): Boolean; override; 167 function GetValueType(const Name: string): TRegValueType; override; 168 function GetValueSize(const Name: string): Integer; override; 146 169 function OpenKey(const Key: string; CreateNew: Boolean): Boolean; override; 147 170 procedure CloseKey; override; … … 169 192 {$ENDIF} 170 193 194 const 195 RegValueTypeName: array[TRegValueType] of string = ('Unknown', 'Integer', 'String', 196 'Binary', 'Float', 'Boolean', 'Text'); 197 171 198 procedure Register; 172 199 … … 215 242 begin 216 243 Result := Registry.ValueExists(Name); 244 end; 245 246 function TWinRegistry.GetKeyInfo(var Value: TRegKeyInfo): Boolean; 247 var 248 KeyInfo: WinRegistry.TRegKeyInfo; 249 begin 250 Result := Registry.GetKeyInfo(KeyInfo); 251 if Result then begin 252 Value.CreationTime := KeyInfo.FileTime; 253 Value.ModificationTime := KeyInfo.FileTime; 254 Value.MaxDataLength := KeyInfo.MaxDataLen; 255 Value.MaxSubKeyLength := KeyInfo.MaxSubKeyLen; 256 Value.MaxValueLength := KeyInfo.MaxValueLen; 257 Value.NumberSubKeys := KeyInfo.NumSubKeys; 258 Value.NumberValues := KeyInfo.NumValues; 259 end; 260 end; 261 262 function TWinRegistry.GetValueInfo(const Name: string; var Value: TRegValueInfo): Boolean; 263 var 264 ValueInfo: WinRegistry.TRegDataInfo; 265 begin 266 Result := Registry.GetDataInfo(Name, ValueInfo); 267 if Result then begin 268 Value.Size := ValueInfo.DataSize; 269 case ValueInfo.RegData of 270 rdUnknown: Value.ValueType := vtUnknown; 271 rdString: Value.ValueType := vtString; 272 rdExpandString: Value.ValueType := vtText; 273 rdBinary: Value.ValueType := vtBinary; 274 rdInteger: Value.ValueType := vtInteger; 275 end; 276 end; 277 end; 278 279 function TWinRegistry.GetValueType(const Name: string): TRegValueType; 280 var 281 ValueInfo: TRegValueInfo; 282 begin 283 if GetValueInfo(Name, ValueInfo) then 284 Result := ValueInfo.ValueType else Result := vtUnknown; 285 end; 286 287 function TWinRegistry.GetValueSize(const Name: string): Integer; 288 begin 289 Result := Registry.GetDataSize(Name); 217 290 end; 218 291 … … 447 520 end; 448 521 522 function TGeneralRegistry.GetKeyInfo(out Value: TRegKeyInfo): Boolean; 523 begin 524 CheckBackend; 525 Result := Backend.GetKeyInfo(Value); 526 end; 527 528 function TGeneralRegistry.GetValueInfo(const Name: string; out Value: TRegValueInfo): Boolean; 529 begin 530 CheckBackend; 531 Result := Backend.GetValueInfo(Name, Value); 532 end; 533 534 function TGeneralRegistry.GetValueType(const Name: string): TRegValueType; 535 begin 536 CheckBackend; 537 Result := Backend.GetValueType(Name); 538 end; 539 540 function TGeneralRegistry.GetValueSize(const Name: string): Integer; 541 begin 542 CheckBackend; 543 Result := Backend.GetValueSize(Name); 544 end; 545 449 546 function TGeneralRegistry.DeleteKey(const Name: string; Recursive: Boolean = False): Boolean; 450 547 begin … … 494 591 CheckBackend; 495 592 Result := Backend.ReadBinaryData(Name, Buffer, BufSize); 593 end; 594 595 function TGeneralRegistry.ReadBoolDefault(const Name: string; 596 const DefaultValue: Boolean): Boolean; 597 begin 598 if ValueExists(Name) then Result := ReadBool(Name) 599 else Result := DefaultValue; 600 end; 601 602 function TGeneralRegistry.ReadDateTimeDefault(const Name: string; 603 const DefaultValue: TDateTime): TDateTime; 604 begin 605 if ValueExists(Name) then Result := ReadDateTime(Name) 606 else Result := DefaultValue; 607 end; 608 609 function TGeneralRegistry.ReadFloatDefault(const Name: string; 610 const DefaultValue: Double): Double; 611 begin 612 if ValueExists(Name) then Result := ReadFloat(Name) 613 else Result := DefaultValue; 614 end; 615 616 function TGeneralRegistry.ReadIntegerDefault(const Name: string; 617 const DefaultValue: Integer): Integer; 618 begin 619 if ValueExists(Name) then Result := ReadInteger(Name) 620 else Result := DefaultValue; 621 end; 622 623 function TGeneralRegistry.ReadStringDefault(const Name: string; 624 const DefaultValue: string): string; 625 begin 626 if ValueExists(Name) then Result := ReadString(Name) 627 else Result := DefaultValue; 496 628 end; 497 629 -
Registry/WinRegistry.pas
r390 r392 1 // FPC windows registry implementation with removed linux xmlregistry imitation 2 1 3 unit WinRegistry; 2 4
Note:
See TracChangeset
for help on using the changeset viewer.