Changeset 12 for trunk/UCore.pas


Ignore:
Timestamp:
Nov 15, 2012, 8:06:57 AM (12 years ago)
Author:
chronos
Message:
  • Přidáno: Další použité komponenty.
  • Přidáno: Modulární systém pro uživatelské zavádění součástí aplikace.
  • Opraveno: Ukládání nastavení do registrů.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UCore.pas

    r7 r12  
    77uses
    88  Registry, Classes, SysUtils, FileUtil, USqlDatabase, URegistry, Forms,
    9   UApplicationInfo, UCoolTranslator, UPersistentForm;
     9  UApplicationInfo, UCoolTranslator, UPersistentForm, UModularSystem,
     10  UFormModuleList;
    1011
    1112type
     
    1718    CoolTranslator1: TCoolTranslator;
    1819    Database: TSqlDatabase;
     20    ModuleManager: TModuleManager;
    1921    procedure DataModuleCreate(Sender: TObject);
    2022    procedure DataModuleDestroy(Sender: TObject);
     23    procedure ModuleManagerUpdate(Sender: TObject);
    2124  private
     25    procedure ModuleManagerChange(Sender: TObject);
    2226  public
     27    FormModuleList: TFormModuleList;
    2328    FormList: TForm;
    2429    PersistentForm: TPersistentForm;
     30    RegistryContext: TRegistryContext;
    2531    procedure Init;
    2632    procedure Done;
    2733    procedure InitData;
    2834    procedure Connect;
    29     procedure LoadFromRegistry(Context: TRegistryContext);
    30     procedure SaveToRegistry(Context: TRegistryContext);
     35    procedure LoadFromRegistry(AContext: TRegistryContext);
     36    procedure SaveToRegistry(AContext: TRegistryContext);
    3137  end;
    3238
     
    3844{$R *.lfm}
    3945
     46uses
     47  URegistredModules;
     48
    4049
    4150{ TCore }
     
    4655  PersistentForm.RegistryContext := RegContext(HKEY(ApplicationInfo1.RegistryRoot),
    4756    ApplicationInfo1.RegistryKey + '\Forms');
     57  ModuleManager := TModuleManager.Create(nil);
     58  RegistryContext := RegContext(HKEY(ApplicationInfo1.RegistryRoot), ApplicationInfo1.RegistryKey);
    4859end;
    4960
    5061procedure TCore.DataModuleDestroy(Sender: TObject);
    5162begin
     63  if Assigned(FormModuleList) then FreeAndNil(FormModuleList);
     64  FreeAndNil(ModuleManager);
    5265  FreeAndNil(PersistentForm);
     66end;
     67
     68procedure TCore.ModuleManagerUpdate(Sender: TObject);
     69begin
     70  if Assigned(FormModuleList) then
     71    FormModuleList.Reload;
     72end;
     73
     74procedure TCore.ModuleManagerChange(Sender: TObject);
     75begin
     76
    5377end;
    5478
    5579procedure TCore.Init;
    5680begin
    57   LoadFromRegistry(RegContext(HKEY(ApplicationInfo1.RegistryRoot), ApplicationInfo1.RegistryKey));
    58 //  LoadFromRegistry(RegContext(HKEY_CURRENT_USER, '\Software\Chronosoft\Dochazka'));
     81  LoadFromRegistry(RegistryContext);
    5982
    60   Connect;
     83    // Init modules
     84    with TRegistryEx.Create do
     85    try
     86      Context := RegistryContext;
     87      RegisterModules(ModuleManager);
     88      if ReadBoolWithDefault('ModuleManagerInstalled', False) then
     89        ModuleManager.LoadFromRegistry(RegContext(RegistryContext.RootKey, RegistryContext.Key + '\Modules'))
     90        else begin
     91          ModuleManager.Modules.Perform([maEnable]);
     92          ModuleManager.SaveToRegistry(RegContext(RegistryContext.RootKey, RegistryContext.Key + '\Modules'));
     93          WriteBool('ModuleManagerInstalled', True);
     94        end;
     95    finally
     96      Free;
     97    end;
     98    ModuleManager.Modules.Perform([maStart], [mcEnabled]);
     99
     100    Connect;
    61101end;
    62102
    63103procedure TCore.Done;
    64104begin
    65   SaveToRegistry(RegContext(HKEY(ApplicationInfo1.RegistryRoot), ApplicationInfo1.RegistryKey));
     105  SaveToRegistry(RegistryContext);
    66106end;
    67107
     
    83123end;
    84124
    85 procedure TCore.LoadFromRegistry(Context: TRegistryContext);
     125procedure TCore.LoadFromRegistry(AContext: TRegistryContext);
    86126begin
    87127  with TRegistryEx.Create do
    88128  try
    89     RootKey := Context.RootKey;
    90     OpenKey('\Software\Chronosoft\Dochazka', True);
    91     //OpenKey(Context.Key, True);
     129    Context := AContext;
    92130    Database.HostName := ReadStringWithDefault('HostName', 'localhost');
    93131    Database.Database := ReadStringWithDefault('Schema', 'dochazka');
     
    100138end;
    101139
    102 procedure TCore.SaveToRegistry(Context: TRegistryContext);
     140procedure TCore.SaveToRegistry(AContext: TRegistryContext);
    103141begin
    104142  with TRegistryEx.Create do
    105143  try
    106     RootKey := Context.RootKey;
    107     OpenKey(Context.Key, True);
     144    Context := AContext;
    108145    WriteString('HostName', Database.HostName);
    109146    WriteString('Schema', Database.Database);
Note: See TracChangeset for help on using the changeset viewer.