Ignore:
Timestamp:
Sep 10, 2022, 6:54:43 PM (20 months ago)
Author:
chronos
Message:
  • Modified: CoolTranslator replaced by Common package.
  • Modified: Update common package.
File:
1 edited

Legend:

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

    r20 r25  
    11unit URegistry;
    2 
    3 {$MODE Delphi}
    42
    53interface
     
    1715    RootKey: HKEY;
    1816    Key: string;
     17    class function Create(RootKey: TRegistryRoot; Key: string): TRegistryContext; static; overload;
     18    class function Create(RootKey: HKEY; Key: string): TRegistryContext; static; overload;
    1919    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;
    2220  end;
    2321
     
    2927    procedure SetCurrentContext(AValue: TRegistryContext);
    3028  public
     29    function ReadChar(const Name: string): Char;
     30    procedure WriteChar(const Name: string; Value: Char);
    3131    function ReadBoolWithDefault(const Name: string;
    3232      DefaultValue: Boolean): Boolean;
    3333    function ReadIntegerWithDefault(const Name: string; DefaultValue: Integer): Integer;
    3434    function ReadStringWithDefault(const Name: string; DefaultValue: string): string;
     35    function ReadCharWithDefault(const Name: string; DefaultValue: Char): Char;
    3536    function ReadFloatWithDefault(const Name: string;
    3637      DefaultValue: Double): Double;
     
    4142    function GetValue(const Name: string; const DefaultValue: Boolean): Boolean; overload;
    4243    function GetValue(const Name: string; const DefaultValue: Double): Double; overload;
     44    function GetValue(const Name: string; const DefaultValue: Char): Char; overload;
    4345    procedure SetValue(const Name: string; const Value: Integer); overload;
    4446    procedure SetValue(const Name: string; const Value: string); overload;
    4547    procedure SetValue(const Name: string; const Value: Boolean); overload;
    4648    procedure SetValue(const Name: string; const Value: Double); overload;
     49    procedure SetValue(const Name: string; const Value: Char); overload;
    4750    property CurrentContext: TRegistryContext read GetCurrentContext write SetCurrentContext;
    4851  end;
     
    5356    HKEY_CURRENT_CONFIG, HKEY_DYN_DATA);
    5457
     58
    5559implementation
    5660
    57 
    5861{ TRegistryContext }
    5962
     
    6366end;
    6467
    65 function TRegistryContext.Create(RootKey: TRegistryRoot; Key: string): TRegistryContext;
     68class function TRegistryContext.Create(RootKey: TRegistryRoot; Key: string): TRegistryContext;
    6669begin
    6770  Result.RootKey := RegistryRootHKEY[RootKey];
     
    6972end;
    7073
    71 function TRegistryContext.Create(RootKey: HKEY; Key: string): TRegistryContext;
     74class function TRegistryContext.Create(RootKey: HKEY; Key: string): TRegistryContext;
    7275begin
    7376  Result.RootKey := RootKey;
     
    97100end;
    98101
     102function TRegistryEx.ReadCharWithDefault(const Name: string; DefaultValue: Char
     103  ): Char;
     104begin
     105  if ValueExists(Name) then Result := ReadChar(Name)
     106    else begin
     107      WriteChar(Name, DefaultValue);
     108      Result := DefaultValue;
     109    end;
     110end;
     111
    99112function TRegistryEx.ReadFloatWithDefault(const Name: string;
    100113  DefaultValue: Double): Double;
     
    131144end;
    132145
     146function TRegistryEx.GetValue(const Name: string; const DefaultValue: Char
     147  ): Char;
     148begin
     149  Result := ReadCharWithDefault(Name, DefaultValue);
     150end;
     151
    133152procedure TRegistryEx.SetValue(const Name: string; const Value: Integer);
    134153begin
     
    149168begin
    150169  WriteFloat(Name, Value);
     170end;
     171
     172procedure TRegistryEx.SetValue(const Name: string; const Value: Char);
     173begin
     174  WriteChar(Name, Value);
    151175end;
    152176
     
    171195function TRegistryEx.OpenKey(const Key: string; CanCreate: Boolean): Boolean;
    172196begin
    173   {$IFDEF Linux}
    174   CloseKey;
     197  {$IFDEF UNIX}
     198  //CloseKey;
    175199  {$ENDIF}
    176200  Result := inherited OpenKey(Key, CanCreate);
     
    179203function TRegistryEx.GetCurrentContext: TRegistryContext;
    180204begin
    181   Result.Key := CurrentPath;
     205  Result.Key := String(CurrentPath);
    182206  Result.RootKey := RootKey;
    183207end;
     
    189213end;
    190214
     215function TRegistryEx.ReadChar(const Name: string): Char;
     216var
     217  S: string;
     218begin
     219  S := ReadString(Name);
     220  if Length(S) > 0 then Result := S[1]
     221    else Result := #0;
     222end;
     223
     224procedure TRegistryEx.WriteChar(const Name: string; Value: Char);
     225begin
     226  WriteString(Name, Value);
     227end;
     228
    191229function TRegistryEx.ReadBoolWithDefault(const Name: string;
    192230  DefaultValue: Boolean): Boolean;
Note: See TracChangeset for help on using the changeset viewer.