Ignore:
Timestamp:
Mar 18, 2022, 1:37:03 PM (2 years ago)
Author:
chronos
Message:
  • Modified: Update Common package.
File:
1 edited

Legend:

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

    r123 r131  
    11unit URegistry;
    22
    3 {$MODE Delphi}
     3{$MODE delphi}
    44
    55interface
     
    1717    RootKey: HKEY;
    1818    Key: string;
    19     class operator Equal(A, B: TRegistryContext): Boolean;
    2019    class function Create(RootKey: TRegistryRoot; Key: string): TRegistryContext; static; overload;
    2120    class function Create(RootKey: HKEY; Key: string): TRegistryContext; static; overload;
     21    class operator Equal(A, B: TRegistryContext): Boolean;
    2222  end;
    2323
     
    2929    procedure SetCurrentContext(AValue: TRegistryContext);
    3030  public
     31    function ReadChar(const Name: string): Char;
     32    procedure WriteChar(const Name: string; Value: Char);
    3133    function ReadBoolWithDefault(const Name: string;
    3234      DefaultValue: Boolean): Boolean;
    3335    function ReadIntegerWithDefault(const Name: string; DefaultValue: Integer): Integer;
    3436    function ReadStringWithDefault(const Name: string; DefaultValue: string): string;
     37    function ReadCharWithDefault(const Name: string; DefaultValue: Char): Char;
    3538    function ReadFloatWithDefault(const Name: string;
    3639      DefaultValue: Double): Double;
     
    8992end;
    9093
     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);
     100      Result := DefaultValue;
     101    end;
     102end;
     103
    91104function TRegistryEx.ReadFloatWithDefault(const Name: string;
    92105  DefaultValue: Double): Double;
     
    119132function TRegistryEx.OpenKey(const Key: string; CanCreate: Boolean): Boolean;
    120133begin
    121   {$IFDEF Linux}
    122   CloseKey;
     134  {$IFDEF UNIX}
     135  //CloseKey;
    123136  {$ENDIF}
    124137  Result := inherited OpenKey(Key, CanCreate);
     
    127140function TRegistryEx.GetCurrentContext: TRegistryContext;
    128141begin
    129   Result.Key := CurrentPath;
     142  Result.Key := String(CurrentPath);
    130143  Result.RootKey := RootKey;
    131144end;
     
    135148  RootKey := AValue.RootKey;
    136149  OpenKey(AValue.Key, True);
     150end;
     151
     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);
    137164end;
    138165
Note: See TracChangeset for help on using the changeset viewer.