Ignore:
Timestamp:
May 8, 2019, 11:54:23 AM (6 years ago)
Author:
chronos
Message:
  • Modified: Build under Lazarus 2.0.
  • Modified: Used .lrj files instead of .lrt files.
  • Modified: Removed TemplateGenerics package.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Packages/Common/URegistry.pas

    r4 r41  
    99
    1010type
    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);
    1813
    1914  { TRegistryContext }
     
    2318    Key: string;
    2419    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;
    2522  end;
    2623
     
    3229    procedure SetCurrentContext(AValue: TRegistryContext);
    3330  public
     31    function ReadChar(const Name: string): Char;
     32    procedure WriteChar(const Name: string; Value: Char);
    3433    function ReadBoolWithDefault(const Name: string;
    3534      DefaultValue: Boolean): Boolean;
    3635    function ReadIntegerWithDefault(const Name: string; DefaultValue: Integer): Integer;
    3736    function ReadStringWithDefault(const Name: string; DefaultValue: string): string;
     37    function ReadCharWithDefault(const Name: string; DefaultValue: Char): Char;
    3838    function ReadFloatWithDefault(const Name: string;
    3939      DefaultValue: Double): Double;
     
    4343  end;
    4444
    45 function RegContext(RootKey: HKEY; Key: string): TRegistryContext;
    46 
     45const
     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);
    4749
    4850implementation
    4951
    50 function RegContext(RootKey: HKEY; Key: string): TRegistryContext;
    51 begin
    52   Result.RootKey := RootKey;
    53   Result.Key := Key;
    54 end;
    5552
    5653{ TRegistryContext }
     
    5956begin
    6057  Result := (A.Key = B.Key) and (A.RootKey = B.RootKey);
     58end;
     59
     60function TRegistryContext.Create(RootKey: TRegistryRoot; Key: string): TRegistryContext;
     61begin
     62  Result.RootKey := RegistryRootHKEY[RootKey];
     63  Result.Key := Key;
     64end;
     65
     66function TRegistryContext.Create(RootKey: HKEY; Key: string): TRegistryContext;
     67begin
     68  Result.RootKey := RootKey;
     69  Result.Key := Key;
    6170end;
    6271
     
    7988    else begin
    8089      WriteString(Name, DefaultValue);
     90      Result := DefaultValue;
     91    end;
     92end;
     93
     94function TRegistryEx.ReadCharWithDefault(const Name: string; DefaultValue: Char
     95  ): Char;
     96begin
     97  if ValueExists(Name) then Result := ReadChar(Name)
     98    else begin
     99      WriteChar(Name, DefaultValue);
    81100      Result := DefaultValue;
    82101    end;
     
    131150end;
    132151
     152function TRegistryEx.ReadChar(const Name: string): Char;
     153var
     154  S: string;
     155begin
     156  S := ReadString(Name);
     157  if Length(S) > 0 then Result := S[1]
     158    else Result := #0;
     159end;
     160
     161procedure TRegistryEx.WriteChar(const Name: string; Value: Char);
     162begin
     163  WriteString(Name, Value);
     164end;
     165
    133166function TRegistryEx.ReadBoolWithDefault(const Name: string;
    134167  DefaultValue: Boolean): Boolean;
Note: See TracChangeset for help on using the changeset viewer.