Changeset 29 for trunk/USystem.pas


Ignore:
Timestamp:
Nov 23, 2011, 8:24:07 PM (13 years ago)
Author:
chronos
Message:
  • Added: Preliminary support for modules.
  • Modified: Database initialization moved to module System.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/USystem.pas

    r28 r29  
    77uses
    88  Classes, SysUtils, SpecializedList, SpecializedDictionary, USqlDatabase,
    9   Strings, UDataTypes, Dialogs, ComCtrls, StdCtrls, Controls, UChronisClient;
     9  Strings, UDataTypes, Dialogs, ComCtrls, StdCtrls, Controls, UChronisClient,
     10  UChronisModule;
    1011
    1112const
     
    105106    Client: TChronisClient;
    106107    Database: TSqlDatabase;
     108    Modules: TListObject; // TListObject<TChronisModule>
     109    ModuleSystem: TChronisModule;
     110    procedure RegisterModule(ModuleClass: TChronisModuleClass);
    107111    function AddType(Name, DataType: string; TypeIndex: TDbValueType): Integer;
    108112    function AddGroup(Name: string; ParentGroupId: Integer = 0): Integer;
     
    132136    function AddModule(Name, Author, Website, Version, Description, License: string): Integer;
    133137    procedure LoadTypes;
     138    function IsDatabaseEmpty: Boolean;
    134139    constructor Create;
    135140    destructor Destroy; override;
     
    235240end;
    236241
     242procedure TChronisBase.RegisterModule(ModuleClass: TChronisModuleClass);
     243begin
     244  Modules.AddNew(ModuleClass.Create);
     245  TChronisModule(Modules.Last).System := TChronisBase(Self);
     246end;
     247
    237248function TChronisBase.AddType(Name, DataType: string; TypeIndex: TDbValueType): Integer;
    238249var
     
    625636end;
    626637
     638function TChronisBase.IsDatabaseEmpty: Boolean;
     639var
     640  DbRows: TDbRows;
     641begin
     642  try
     643    DbRows := TDbRows.Create;
     644    Database.Query(DbRows, 'SELECT 1 FROM information_schema.tables WHERE table_name = "Information" AND table_schema = "' +
     645      Database.Database + '"');
     646    Result := DbRows.Count = 0;
     647  finally
     648    DbRows.Free;
     649  end;
     650end;
     651
    627652constructor TChronisBase.Create;
    628653begin
    629654  Types := TChronisTypeList.Create;
     655  Modules := TListObject.Create;
    630656  Client := nil;
    631657end;
     
    634660begin
    635661  Types.Free;
     662  Modules.Free;
    636663  Client.Free;
    637664  inherited Destroy;
Note: See TracChangeset for help on using the changeset viewer.