(************************************************************************
*    This File is Part of the AHM Triton Tools                          *
*    for Borland Delphi and C++ Builder.                                *
*************************************************************************
* Copyright © 1995-1999 Alexander H. Mehlhorn (AHM) and Tritontools.com *
* All Rights reserved.                                                  *
*                                                                       *
*    For more Information contact us at                                 *
*    E-Mail : support@tritontools.com                                   *
*    URL : http://www.tritontools.com                                   *
*                                                                       *
*    AHM is copyright by Alexander H. Mehlhorn                          *
*    All Parts of this Collection were developed,                       *
*    designed and implemented by AHM                                    *
*                                                                       *
*    Under no Circumstances may you distribute this file                *
*    in this or any other format. This File is supplied                 *
*    as Evaluation of Source only. No Delphi Components may be developed*
*    using extracts or subsets of this code without expressed permission*
*    by AHM.                                                            *
*                                                                       *
*************************************************************************)
unit AHMTStoreData;

interface

uses SysUtils, Windows, Messages, Classes,Dialogs,Inifiles,Registry,AHMSystemClass,Graphics;

type
  TAHMRootKey = (hkeyClassesRoot,hkeyCurrentUser,hkeyLocalMachine,hkeyUsers,
                 hkeyCurrentConfig, hkeyDynData);
const
  AHMHKeys : array[TAHMRootKey] of HKEY = (HKEY_CLASSES_ROOT, HKEY_CURRENT_USER,
             HKEY_LOCAL_MACHINE, HKEY_USERS, HKEY_CURRENT_CONFIG, HKEY_DYN_DATA);
type
  TAHMDatatype = (sRegistry,sIniFile);
  TAHMRegistry = class(TPersistent)
  private
    FRootKey : TAHMRootKey;
    FPath  : string;
    procedure SetPath(const Value: String);
  protected
  public
    Constructor Create;
    Destructor Destroy; override;
  published
    Property Rootkey : TAHMRootkey read FRootkey Write FRootkey default hkeyCurrentUser;
    Property Path : String read FPath write SetPath;
  end;
  TAHMIniFile = class(TPersistent)
  private
    FFilename : String;
  public
    Constructor Create;
    Destructor Destroy; override;
  published
    Property IniFilename : String read FFilename write FFilename;
  end;
  TAHMDataStore = class(TPersistent)
  private
    FEnabled : Boolean;
    FDatatype : TAHMDatatype;
    FRegistry : TAHMRegistry;
    FIniFile : TAHMIniFile;
    FOnError : TNotifyEvent;
    FSection: String;
    FPassword: String;
    procedure SetPassword(const Value: String);
  public
    Constructor Create;
    Destructor Destroy; override;
  published
    Property OnError : TNotifyevent read FOnError write FOnError;
    Property Enabled : Boolean read FEnabled write FEnabled default True;
    Property Section : String read FSection write FSection;
    Property Password : String read FPassword write SetPassword; 
    Property Datatype : TAHMDatatype read FDatatype write FDatatype default sRegistry;
    Property Registry : TAHMRegistry read FRegistry write FRegistry;
    Property Inifile : TAHMIniFile read FInifile write FInifile;
  end;
  TAHMStoreData = class(TAHMSystemsComponent)
  private
    FOnError  : TNotifyevent;
    FDataStore : TAHMDataStore;
  protected
  public
    Constructor Create(AOwner: TComponent); override;
    Destructor Destroy; override;
    {Functions}
    Function  ReadStr  (Key : String;Error : String) : String;
    Function  ReadVariant(Key : String;Error : Variant) : Variant;
    Function  ReadInt  (Key : String;Error : Integer) : Integer;
    Function  ReadBool (Key : String;Error : Boolean) : Boolean;
    Function ReadColor(Key : String;Error : TColor) : TColor;
    Function ReadTime(Key : String;Error : TDateTime) : TDateTime;
    Function ReadDate(Key : String;Error : TDateTime) : TDateTime;
    Function ReadDateTime(Key : String;Error : TDateTime) : TDateTime;
    Function ReadCrypt (Key : String;Error : String) : String;
    {Procedures}
    Procedure WriteCrypt(Key : String;Value : String);
    Procedure ReadStrs(var Values :TStringList);
    Procedure WriteTime(Key : String;Value : TDateTime);
    Procedure WriteDate(Key : String;Value : TDateTime);
    Procedure WriteDateTime(Key : String;Value : TDateTime);
    Procedure WriteVariant  (Key : String;Value : Variant);
    Procedure WriteStr  (Key : String;Value : string);
    Procedure WriteInt  (Key : String;Value : Integer);
    Procedure WriteColor(Key : String;Value : TColor);
    Procedure WriteBool (Key : String;Value : Boolean);
    Procedure DeleteKey(Key : String);
    Procedure Erase;
 published
    Property OnError : TNotifyevent read FOnError write FOnError;
    Property DataStore : TAHMDataStore read FDataStore write FDataStore;
  end;


implementation

{Class TAHMRegistry of the AHM Add-Ons for Delphi, C++Builder written 1998 by AHM}

Function Encrypts(Value,Password : String): string;
var ii : integer;
begin
  result:='';
  Value:=concat(Value,Password);
  if length(Value)>0 then
  for ii:=1 to length(Value) do result:=result+chr(ord(Value[ii])+71);
end;

Function Decrypts(Value,Password,Error : String):String;
var ii : integer;
begin
  result:='';
  if length(Value)>0 then for ii:=1 to length(Value) do Result:=result+chr(ord(Value[ii])-71);
  if copy(result,Length(result)-Length(Password)+1,Length(Password))<>Password then
     result:=Error else Delete(Result,Length(result)-Length(Password)+1,Length(Password));
end;

Constructor TAHMRegistry.Create;
begin
  FRootKey := hkeyCurrentUser;
  FPath := '\Software\Company\Product';
  inherited Create;
end;

Destructor TAHMRegistry.Destroy;
begin
  inherited Destroy;
end;

{Class TAHMInifile of the AHM Add-Ons for Delphi, C++Builder written 1998 by AHM}
Constructor TAHMIniFile.Create;
begin
  FFilename := 'MyFile.ini';
  inherited Create;
end;

Destructor TAHMIniFile.Destroy;
begin
  inherited Destroy;
end;

{Class TAHMStore of the AHM Add-Ons for Delphi, C++Builder written 1998 by AHM}
Constructor TAHMDataStore.Create;
begin
  inherited Create;
  FEnabled:=True;
  FSection  := 'MySection';
  FDatatype:=sRegistry;
  FPassword:='Password';
  FRegistry:=TAHMRegistry.Create;
  FIniFile:=TAHMIniFile.Create;
end;

Destructor TAHMDataStore.Destroy;
begin
  FRegistry.Free;
  FIniFile.Free;
  inherited Destroy;
end;

Function TAHMStoreData.ReadStr(Key : String;Error : String):String;
begin
  Result:=Error;
  if FDataStore.Enabled then
  if (FDataStore.FSection<>'') then
  begin
    case FDataStore.FDatatype of
      sRegistry : if (FDataStore.FRegistry.FPath <> '') then
                  with TRegIniFile.Create(FDataStore.FRegistry.Fpath) do
                  try
                    RootKey := AHMHKeys[FDataStore.FRegistry.FRootKey];
                    OpenKey(FDataStore.FRegistry.FPath,True); 
                    result:=ReadString(FDataStore.FSection,Key,Error);
                    if (result=Error) and assigned(FOnError) then FOnError(self);
                    closekey;
                  finally
                    Free;
                  end;
      sIniFile  : if (FDataStore.FIniFile.FFilename <> '') then
                  with TInifile.Create(FDataStore.FIniFile.FFilename) do
                  try
                    result:=ReadString(FDataStore.FSection,Key,Error);
                    if (result=Error) and assigned(FOnError) then FOnError(self);
                  finally
                    Free;
                  end;
    end;
  end else if assigned(FOnError) then FOnError(Self);
end;

Procedure TAHMStoreData.ReadStrs(var Values :TStringList);
begin
  if FDataStore.Enabled then
  if (FDataStore.FSection<>'') then
  begin
    case FDataStore.FDatatype of
      sRegistry : if (FDataStore.FRegistry.FPath <> '') then
                  with TRegIniFile.Create(FDataStore.FRegistry.FPath) do
                  try
                    RootKey := AHMHKeys[FDataStore.FRegistry.FRootKey];
                    OpenKey(FDataStore.FRegistry.FPath,True); 
                    ReadSectionValues(FDataStore.FSection,Values);
                    closeKey;
                  finally
                    Free;
                  end;
      sIniFile  : if (FDataStore.FIniFile.FFilename <> '') then
                  with TInifile.Create(FDataStore.FIniFile.FFilename) do
                  try
                    ReadSectionValues(FDataStore.FSection,Values);
                  finally
                    Free;
                  end;
    end;
  end else if assigned(FOnError) then FOnError(Self);
end;

Function TAHMStoreData.ReadCrypt(Key : String;Error : String) : String;
begin
  Result:=Error;
  if FDataStore.Enabled then
  if (FDataStore.FSection<>'') then
  begin
    case FDataStore.FDatatype of
      sRegistry : if (FDataStore.FRegistry.FPath <> '') then
                  with TRegIniFile.Create(FDataStore.FRegistry.FPath) do
                  try
                    RootKey := AHMHKeys[FDataStore.FRegistry.FRootKey];
                    OpenKey(FDataStore.FRegistry.FPath,True); 
                    result:=ReadString(FDataStore.FSection,Key,Error);
                    result:=Decrypts(Result,FDataStore.FPassword,Error);
                    if (result=Error) and assigned(FOnError) then FOnError(self);
                    CloseKey;
                  finally
                    Free;
                  end;
      sIniFile  : if (FDataStore.FIniFile.FFilename <> '') then
                  with TInifile.Create(FDataStore.FIniFile.FFilename) do
                  try
                    result:=ReadString(FDataStore.FSection,Key,Error);
                    result:=Decrypts(Result,FDataStore.FPassword,Error);
                    if (result=Error) and assigned(FOnError) then FOnError(self);
                  finally
                    Free;
                  end;
    end;
  end else if assigned(FOnError) then FOnError(Self);
end;

Procedure TAHMStoreData.WriteCrypt(Key : String;Value : string);
begin
  if FDataStore.Enabled then
  if (FDataStore.FSection<>'') then
  begin
    case FDataStore.FDatatype of
      sRegistry : if (FDataStore.FRegistry.FPath <> '') then
                  with TRegIniFile.Create(FDataStore.FRegistry.FPath) do
                  try
                    RootKey := AHMHKeys[FDataStore.FRegistry.FRootKey];
                    OpenKey(FDataStore.FRegistry.FPath,True); 
                    WriteString(FDataStore.FSection,Key,Encrypts(Value,FDataStore.FPassword));
                    CloseKey;
                  finally
                    Free;
                  end;
      sIniFile  : if (FDataStore.FIniFile.FFilename <> '') then
                  with TInifile.Create(FDataStore.FIniFile.FFilename) do
                  try
                    WriteString(FDataStore.FSection,Key,Encrypts(Value,FDataStore.FPassword));
                  finally
                    Free;
                  end;
    end;
  end else if assigned(FOnError) then FOnError(Self);
end;


Procedure TAHMStoreData.WriteStr(Key : String;Value : string);
begin
  if FDataStore.Enabled then
  if (FDataStore.FSection<>'') then
  begin
    case FDataStore.FDatatype of
      sRegistry : if (FDataStore.FRegistry.FPath <> '') then
                  with TRegIniFile.Create(FDataStore.FRegistry.FPath) do
                  try
                    RootKey := AHMHKeys[FDataStore.FRegistry.FRootKey];
                    OpenKey(FDataStore.FRegistry.FPath,True); 
                    WriteString(FDataStore.FSection,Key,Value);
                    CloseKey;
                  finally
                    Free;
                  end;
      sIniFile  : if (FDataStore.FIniFile.FFilename <> '') then
                  with TInifile.Create(FDataStore.FIniFile.FFilename) do
                  try
                    WriteString(FDataStore.FSection,Key,Value);
                  finally
                    Free;
                  end;
    end;
  end else if assigned(FOnError) then FOnError(Self);
end;

Function TAHMStoreData.ReadInt(Key : String;Error : Integer):Integer;
begin
  Result:=Error;
  if FDataStore.Enabled then
  if (FDataStore.FSection<>'') then
  begin
    case FDataStore.FDatatype of
      sRegistry : if (FDataStore.FRegistry.FPath <> '') then
                  with TRegIniFile.Create(FDataStore.FRegistry.FPath) do
                  try
                    RootKey := AHMHKeys[FDataStore.FRegistry.FRootKey];
                    OpenKey(FDataStore.FRegistry.FPath,True); 
                    result:=ReadInteger(FDataStore.FSection,Key,Error);
                    if (result=Error) and assigned(FOnError) then FOnError(self);
                    CloseKey;
                  finally
                    Free;
                  end;
      sIniFile  : if (FDataStore.FIniFile.FFilename <> '') then
                  with TInifile.Create(FDataStore.FIniFile.FFilename) do
                  try
                    result:=ReadInteger(FDataStore.FSection,Key,Error);
                    if (result=Error) and assigned(FOnError) then FOnError(self);
                  finally
                    Free;
                  end;
    end;
  end else if assigned(FOnError) then FOnError(Self);
end;

Procedure TAHMStoreData.WriteInt(Key : String;Value : Integer);
begin
  if FDataStore.Enabled then
  if (FDataStore.FSection<>'') then
  begin
    case FDataStore.FDatatype of
      sRegistry : if (FDataStore.FRegistry.FPath <> '') then
                  with TRegIniFile.Create(FDataStore.FRegistry.FPath) do
                  try
                    RootKey := AHMHKeys[FDataStore.FRegistry.FRootKey];
                    OpenKey(FDataStore.FRegistry.FPath,True); 
                    WriteInteger(FDataStore.FSection,Key,Value);
                    CloseKey;
                  finally
                    Free;
                  end;
      sIniFile  : if (FDataStore.FIniFile.FFilename <> '') then
                  with TInifile.Create(FDataStore.FIniFile.FFilename) do
                  try
                    WriteInteger(FDataStore.FSection,Key,Value);
                  finally
                    Free;
                  end;
    end;
  end else if assigned(FOnError) then FOnError(Self);
end;

Function TAHMStoreData.ReadBool(Key : String;Error : Boolean) : Boolean;
begin
  result:=Error;
  if FDataStore.Enabled then
  if (FDataStore.FSection<>'') then
  begin
    case FDataStore.FDatatype of
      sRegistry : if (FDataStore.FRegistry.FPath <> '') then
                  with TRegIniFile.Create(FDataStore.FRegistry.FPath) do
                  try
                    RootKey := AHMHKeys[FDataStore.FRegistry.FRootKey];
                    OpenKey(FDataStore.FRegistry.FPath,True); 
                    result:=ReadBool(FDataStore.FSection,Key,Error);
                    CloseKey;
                  finally
                    Free;
                  end;
      sIniFile  : if (FDataStore.FIniFile.FFilename <> '') then
                  with TInifile.Create(FDataStore.FIniFile.FFilename) do
                  try
                    result:=ReadBool(FDataStore.FSection,Key,Error);
                  finally
                    Free;
                  end;
    end;
  end else if assigned(FOnError) then FOnError(Self);
end;


Procedure TAHMStoreData.WriteBool(Key : String;Value : Boolean);
begin
  if FDataStore.Enabled then
  if (FDataStore.FSection<>'') then
  begin
    case FDataStore.FDatatype of
      sRegistry : if (FDataStore.FRegistry.FPath <> '') then
                  with TRegIniFile.Create(FDataStore.FRegistry.FPath) do
                  try
                    RootKey := AHMHKeys[FDataStore.FRegistry.FRootKey];
                    OpenKey(FDataStore.FRegistry.FPath,True); 
                    WriteBool(FDataStore.FSection,Key,Value);
                    CloseKey;
                  finally
                    Free;
                  end;
      sIniFile  : if (FDataStore.FIniFile.FFilename <> '') then
                  with TInifile.Create(FDataStore.FIniFile.FFilename) do
                  try
                    WriteBool(FDataStore.FSection,Key,Value);
                  finally
                    Free;
                  end;
    end;
  end else if assigned(FOnError) then FOnError(Self);
end;

Procedure TAHMStoreData.Erase;
begin
  if FDataStore.Enabled then
  if (FDataStore.FSection<>'') then
  begin
    case FDataStore.FDatatype of
      sRegistry : if (FDataStore.FRegistry.FPath <> '') then
                  with TRegIniFile.Create(FDataStore.FRegistry.FPath) do
                  try
                    RootKey := AHMHKeys[FDataStore.FRegistry.FRootKey];
                    OpenKey(FDataStore.FRegistry.FPath,True); 
                    Erasesection(FDataStore.FSection);
                    CloseKey;
                  finally
                    Free;
                  end;
      sIniFile  : if (FDataStore.FIniFile.FFilename <> '') then
                  with TInifile.Create(FDataStore.FIniFile.FFilename) do
                  try
                    Erasesection(FDataStore.FSection);
                  finally
                    Free;
                  end;
    end;
  end else if assigned(FOnError) then FOnError(Self);
end;

Procedure TAHMStoreData.DeleteKey(Key : String);
begin
  if FDataStore.Enabled then
  if (FDataStore.FSection<>'') then
  begin
    case FDataStore.FDatatype of
      sRegistry : if (FDataStore.FRegistry.FPath <> '') then
                  with TRegIniFile.Create(FDataStore.FRegistry.FPath) do
                  try
                    RootKey := AHMHKeys[FDataStore.FRegistry.FRootKey];
                    OpenKey(FDataStore.FRegistry.FPath,True); 
                    Deletekey(FDataStore.FSection,Key);
                    CloseKey;
                  finally
                    Free;
                  end;
      sIniFile  : if (FDataStore.FIniFile.FFilename <> '') then
                  with TInifile.Create(FDataStore.FIniFile.FFilename) do
                  try
                    Deletekey(FDataStore.FSection,Key);
                  finally
                    Free;
                  end;
    end;
  end else if assigned(FOnError) then FOnError(Self);
end;


Constructor TAHMStoreData.Create;
begin
  inherited Create(AOwner);
  FDataStore := TAHMDataStore.Create;
end;

Destructor TAHMStoreData.Destroy;
begin
  FDataStore.Free;
  inherited Destroy;
end;

procedure TAHMRegistry.SetPath(const Value: String);
begin
  FPath := Value;
  if Fpath<>'' then
  begin
    while pos('/',FPath)>0 do FPath[pos('/',FPath)]:='\';
    if FPath[1]<>'\' then FPath:='\'+FPath;
  end;
end;

procedure TAHMDataStore.SetPassword(const Value: String);
begin
  if Value<>'' then FPassword := Value else FPassword:='Password';
end;

function TAHMStoreData.ReadColor(Key: String; Error: TColor): TColor;
begin
  Result:=Error;
  if FDataStore.Enabled then
  if (FDataStore.FSection<>'') then
  begin
    case FDataStore.FDatatype of
      sRegistry : if (FDataStore.FRegistry.FPath <> '') then
                  with TRegIniFile.Create(FDataStore.FRegistry.Fpath) do
                  try
                    RootKey := AHMHKeys[FDataStore.FRegistry.FRootKey];
                    OpenKey(FDataStore.FRegistry.FPath,True); 
                    result:=StringToColor(ReadString(FDataStore.FSection,Key,ColorToString(Error)));
                    if (result=Error) and assigned(FOnError) then FOnError(self);
                    closekey;
                  finally
                    Free;
                  end;
      sIniFile  : if (FDataStore.FIniFile.FFilename <> '') then
                  with TInifile.Create(FDataStore.FIniFile.FFilename) do
                  try
                    result:=StringToColor(ReadString(FDataStore.FSection,Key,ColorToString(Error)));
                    if (result=Error) and assigned(FOnError) then FOnError(self);
                  finally
                    Free;
                  end;
    end;
  end else if assigned(FOnError) then FOnError(Self);
end;

procedure TAHMStoreData.WriteColor(Key: String; Value: TColor);
begin
  if FDataStore.Enabled then
  if (FDataStore.FSection<>'') then
  begin
    case FDataStore.FDatatype of
      sRegistry : if (FDataStore.FRegistry.FPath <> '') then
                  with TRegIniFile.Create(FDataStore.FRegistry.FPath) do
                  try
                    RootKey := AHMHKeys[FDataStore.FRegistry.FRootKey];
                    OpenKey(FDataStore.FRegistry.FPath,True); 
                    WriteString(FDataStore.FSection,Key,ColorToString(Value));
                    CloseKey;
                  finally
                    Free;
                  end;
      sIniFile  : if (FDataStore.FIniFile.FFilename <> '') then
                  with TInifile.Create(FDataStore.FIniFile.FFilename) do
                  try
                    WriteString(FDataStore.FSection,Key,ColorToString(Value));
                  finally
                    Free;
                  end;
    end;
  end else if assigned(FOnError) then FOnError(Self);
end;

function TAHMStoreData.ReadDate(Key: String; Error: TDateTime): TDateTime;
begin
  Result:=Error;
  if FDataStore.Enabled then
  if (FDataStore.FSection<>'') then
  begin
    case FDataStore.FDatatype of
      sRegistry : if (FDataStore.FRegistry.FPath <> '') then
                  with TRegIniFile.Create(FDataStore.FRegistry.Fpath) do
                  try
                    RootKey := AHMHKeys[FDataStore.FRegistry.FRootKey];
                    OpenKey(FDataStore.FRegistry.FPath,True); 
                    result:=StrToDate(ReadString(FDataStore.FSection,Key,DateToStr(Error)));
                    if (result=Error) and assigned(FOnError) then FOnError(self);
                    closekey;
                  finally
                    Free;
                  end;
      sIniFile  : if (FDataStore.FIniFile.FFilename <> '') then
                  with TInifile.Create(FDataStore.FIniFile.FFilename) do
                  try
                    result:=StrToDate(ReadString(FDataStore.FSection,Key,DateToStr(Error)));
                    if (result=Error) and assigned(FOnError) then FOnError(self);
                  finally
                    Free;
                  end;
    end;
  end else if assigned(FOnError) then FOnError(Self);
end;

function TAHMStoreData.ReadDateTime(Key: String;
  Error: TDateTime): TDateTime;
begin
  Result:=Error;
  if FDataStore.Enabled then
  if (FDataStore.FSection<>'') then
  begin
    case FDataStore.FDatatype of
      sRegistry : if (FDataStore.FRegistry.FPath <> '') then
                  with TRegIniFile.Create(FDataStore.FRegistry.Fpath) do
                  try
                    RootKey := AHMHKeys[FDataStore.FRegistry.FRootKey];
                    OpenKey(FDataStore.FRegistry.FPath,True); 
                    result:=StrToDateTime(ReadString(FDataStore.FSection,Key,DateTimeToStr(Error)));
                    if (result=Error) and assigned(FOnError) then FOnError(self);
                    closekey;
                  finally
                    Free;
                  end;
      sIniFile  : if (FDataStore.FIniFile.FFilename <> '') then
                  with TInifile.Create(FDataStore.FIniFile.FFilename) do
                  try
                    result:=StrToDateTime(ReadString(FDataStore.FSection,Key,DateTimeToStr(Error)));
                    if (result=Error) and assigned(FOnError) then FOnError(self);
                  finally
                    Free;
                  end;
    end;
  end else if assigned(FOnError) then FOnError(Self);
end;

function TAHMStoreData.ReadTime(Key: String; Error: TDateTime): TDateTime;
begin
  Result:=Error;
  if FDataStore.Enabled then
  if (FDataStore.FSection<>'') then
  begin
    case FDataStore.FDatatype of
      sRegistry : if (FDataStore.FRegistry.FPath <> '') then
                  with TRegIniFile.Create(FDataStore.FRegistry.Fpath) do
                  try
                    RootKey := AHMHKeys[FDataStore.FRegistry.FRootKey];
                    OpenKey(FDataStore.FRegistry.FPath,True); 
                    result:=StrToTime(ReadString(FDataStore.FSection,Key,TimeToStr(Error)));
                    if (result=Error) and assigned(FOnError) then FOnError(self);
                    closekey;
                  finally
                    Free;
                  end;
      sIniFile  : if (FDataStore.FIniFile.FFilename <> '') then
                  with TInifile.Create(FDataStore.FIniFile.FFilename) do
                  try
                    result:=StrToTime(ReadString(FDataStore.FSection,Key,TimeToStr(Error)));
                    if (result=Error) and assigned(FOnError) then FOnError(self);
                  finally
                    Free;
                  end;
    end;
  end else if assigned(FOnError) then FOnError(Self);
end;

procedure TAHMStoreData.WriteDate(Key: String; Value: TDateTime);
begin
  if FDataStore.Enabled then
  if (FDataStore.FSection<>'') then
  begin
    case FDataStore.FDatatype of
      sRegistry : if (FDataStore.FRegistry.FPath <> '') then
                  with TRegIniFile.Create(FDataStore.FRegistry.FPath) do
                  try
                    RootKey := AHMHKeys[FDataStore.FRegistry.FRootKey];
                    OpenKey(FDataStore.FRegistry.FPath,True); 
                    WriteString(FDataStore.FSection,Key,DateToStr(Value));
                    CloseKey;
                  finally
                    Free;
                  end;
      sIniFile  : if (FDataStore.FIniFile.FFilename <> '') then
                  with TInifile.Create(FDataStore.FIniFile.FFilename) do
                  try
                    WriteString(FDataStore.FSection,Key,DateToStr(Value));
                  finally
                    Free;
                  end;
    end;
  end else if assigned(FOnError) then FOnError(Self);
end;

procedure TAHMStoreData.WriteDateTime(Key: String; Value: TDateTime);
begin
  if FDataStore.Enabled then
  if (FDataStore.FSection<>'') then
  begin
    case FDataStore.FDatatype of
      sRegistry : if (FDataStore.FRegistry.FPath <> '') then
                  with TRegIniFile.Create(FDataStore.FRegistry.FPath) do
                  try
                    RootKey := AHMHKeys[FDataStore.FRegistry.FRootKey];
                    OpenKey(FDataStore.FRegistry.FPath,True); 
                    WriteString(FDataStore.FSection,Key,DateTimeToStr(Value));
                    CloseKey;
                  finally
                    Free;
                  end;
      sIniFile  : if (FDataStore.FIniFile.FFilename <> '') then
                  with TInifile.Create(FDataStore.FIniFile.FFilename) do
                  try
                    WriteString(FDataStore.FSection,Key,DateTimeToStr(Value));
                  finally
                    Free;
                  end;
    end;
  end else if assigned(FOnError) then FOnError(Self);
end;

procedure TAHMStoreData.WriteTime(Key: String; Value: TDateTime);
begin
  if FDataStore.Enabled then
  if (FDataStore.FSection<>'') then
  begin
    case FDataStore.FDatatype of
      sRegistry : if (FDataStore.FRegistry.FPath <> '') then
                  with TRegIniFile.Create(FDataStore.FRegistry.FPath) do
                  try
                    RootKey := AHMHKeys[FDataStore.FRegistry.FRootKey];
                    OpenKey(FDataStore.FRegistry.FPath,True); 
                    WriteString(FDataStore.FSection,Key,TimeToStr(Value));
                    CloseKey;
                  finally
                    Free;
                  end;
      sIniFile  : if (FDataStore.FIniFile.FFilename <> '') then
                  with TInifile.Create(FDataStore.FIniFile.FFilename) do
                  try
                    WriteString(FDataStore.FSection,Key,TimeToStr(Value));
                  finally
                    Free;
                  end;
    end;
  end else if assigned(FOnError) then FOnError(Self);
end;

function TAHMStoreData.ReadVariant(Key: String; Error: Variant): Variant;
begin
  Result:=Error;
  if FDataStore.Enabled then
  if (FDataStore.FSection<>'') then
  begin
    case FDataStore.FDatatype of
      sRegistry : if (FDataStore.FRegistry.FPath <> '') then
                  with TRegIniFile.Create(FDataStore.FRegistry.Fpath) do
                  try
                    RootKey := AHMHKeys[FDataStore.FRegistry.FRootKey];
                    OpenKey(FDataStore.FRegistry.FPath,True); 
                    result:=Variant(ReadString(FDataStore.FSection,Key,String(Error)));
                    if (result=Error) and assigned(FOnError) then FOnError(self);
                    closekey;
                  finally
                    Free;
                  end;
      sIniFile  : if (FDataStore.FIniFile.FFilename <> '') then
                  with TInifile.Create(FDataStore.FIniFile.FFilename) do
                  try
                    result:=Variant(ReadString(FDataStore.FSection,Key,String(Error)));
                    if (result=Error) and assigned(FOnError) then FOnError(self);
                  finally
                    Free;
                  end;
    end;
  end else if assigned(FOnError) then FOnError(Self);
end;

procedure TAHMStoreData.WriteVariant(Key: String; Value: Variant);
begin
  if FDataStore.Enabled then
  if (FDataStore.FSection<>'') then
  begin
    case FDataStore.FDatatype of
      sRegistry : if (FDataStore.FRegistry.FPath <> '') then
                  with TRegIniFile.Create(FDataStore.FRegistry.FPath) do
                  try
                    RootKey := AHMHKeys[FDataStore.FRegistry.FRootKey];
                    OpenKey(FDataStore.FRegistry.FPath,True); 
                    WriteString(FDataStore.FSection,Key,String(Value));
                    CloseKey;
                  finally
                    Free;
                  end;
      sIniFile  : if (FDataStore.FIniFile.FFilename <> '') then
                  with TInifile.Create(FDataStore.FIniFile.FFilename) do
                  try
                    WriteString(FDataStore.FSection,Key,String(Value));
                  finally
                    Free;
                  end;
    end;
  end else if assigned(FOnError) then FOnError(Self);
end;

end.
