Changeset 59 for trunk/UCore.pas


Ignore:
Timestamp:
Nov 16, 2012, 9:59:56 AM (12 years ago)
Author:
chronos
Message:
  • Fixed: Store module settings in system registry.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UCore.pas

    r58 r59  
    1111
    1212type
     13  TChronisPlatform = class;
    1314
    1415  { TCore }
    1516
    1617  TCore = class(TDataModule)
    17     ApplicationInfo1: TApplicationInfo;
    1818    CoolTranslator1: TCoolTranslator;
    1919    Database: TSqlDatabase;
     
    2323    procedure ModuleManagerUpdate(Sender: TObject);
    2424  private
     25    FRegistryContext: TRegistryContext;
     26    procedure SetRegistryContext(AValue: TRegistryContext);
    2527  public
     28    Platform: TChronisPlatform;
    2629    FormModuleList: TFormModuleList;
    2730    FormList: TForm;
    2831    PersistentForm: TPersistentForm;
    29     RegistryContext: TRegistryContext;
    3032    procedure Init;
    3133    procedure Done;
     
    3436    procedure LoadFromRegistry(AContext: TRegistryContext);
    3537    procedure SaveToRegistry(AContext: TRegistryContext);
     38    property RegistryContext: TRegistryContext read FRegistryContext
     39      write SetRegistryContext;
    3640  end;
    3741
     
    3943
    4044  TChronisPlatform = class(TComponent)
     45  private
     46    FOnRegisterModules: TNotifyEvent;
     47    FOnUnregisterModules: TNotifyEvent;
     48    FRegistryContext: TRegistryContext;
     49    procedure SetRegistryContext(AValue: TRegistryContext);
    4150  public
    4251    constructor Create(AOwner: TComponent); override;
     
    4453    procedure Init;
    4554    procedure Done;
     55    property RegistryContext: TRegistryContext read FRegistryContext
     56      write SetRegistryContext;
     57  published
     58    property OnRegisterModules: TNotifyEvent read FOnRegisterModules
     59      write FOnRegisterModules;
     60    property OnUnregisterModules: TNotifyEvent read FOnUnregisterModules
     61      write FOnUnregisterModules;
    4662  end;
    4763
     
    5672
    5773uses
    58   UFormMain, UFormConnection;
     74  UFormMain, UFormConnection, UFormSetting;
    5975
    6076procedure Register;
     
    6581{ TChronisPlatform }
    6682
     83procedure TChronisPlatform.SetRegistryContext(AValue: TRegistryContext);
     84begin
     85  if FRegistryContext = AValue then Exit;
     86  FRegistryContext := AValue;
     87  if Assigned(Core) then Core.RegistryContext := AValue;
     88end;
     89
    6790constructor TChronisPlatform.Create(AOwner: TComponent);
    6891begin
     
    78101begin
    79102  Application.CreateForm(TCore, Core);
    80   Application.CreateForm(TFormMain, FormMain);
     103  Core.Platform := Self;
     104  Core.RegistryContext := FRegistryContext;
     105  Application.CreateForm(TFormMain, FormMain); // first form
    81106  Application.CreateForm(TFormConnection, FormConnection);
     107  Application.CreateForm(TFormSetting, FormSetting);
    82108  //Core := TCore.Create(Application);
    83109  //FormMain := TFormMain.Create(Application);
     
    87113procedure TChronisPlatform.Done;
    88114begin
    89   FormConnection.Free;
    90   FormMain.Free;
    91   Core.Free;
     115(*  FreeAndNil(FormSetting);
     116  FreeAndNil(FormConnection);
     117  FreeAndNil(FormMain);
     118  FreeAndNil(Core); *)
    92119end;
    93120
     
    98125begin
    99126  PersistentForm := TPersistentForm.Create;
    100   PersistentForm.RegistryContext := RegContext(HKEY(ApplicationInfo1.RegistryRoot),
    101     ApplicationInfo1.RegistryKey + '\Forms');
    102   RegistryContext := RegContext(HKEY(ApplicationInfo1.RegistryRoot), ApplicationInfo1.RegistryKey);
    103127end;
    104128
     
    113137    FormModuleList.Reload;
    114138  FormMain.ReloadPages;
     139end;
     140
     141procedure TCore.SetRegistryContext(AValue: TRegistryContext);
     142begin
     143  if (FRegistryContext.RootKey = AValue.RootKey) and
     144    (FRegistryContext.Key = AValue.Key) then Exit;
     145  FRegistryContext := AValue;
     146  PersistentForm.RegistryContext := RegContext(RegistryContext.RootKey,
     147    RegistryContext.Key + '\Forms');
    115148end;
    116149
     
    126159    try
    127160      Context := RegistryContext;
    128       //RegisterModules(ModuleManager);
     161      if Assigned(Platform.OnRegisterModules) then
     162        Platform.OnRegisterModules(Self);
    129163      if ReadBoolWithDefault('ModuleManagerInstalled', False) then
    130164        ModuleManager.LoadFromRegistry(RegContext(RegistryContext.RootKey, RegistryContext.Key + '\Modules'))
     
    151185  if Assigned(FormModuleList) then FreeAndNil(FormModuleList);
    152186  ModuleManager.OnUpdate := nil;
    153   //UnregisterModules(ModuleManager);
     187  if Assigned(Platform.OnUnregisterModules) then
     188    Platform.OnUnregisterModules(Self);
    154189end;
    155190
Note: See TracChangeset for help on using the changeset viewer.