Changeset 7 for trunk/UDatabase.pas


Ignore:
Timestamp:
Jan 20, 2015, 11:33:39 PM (10 years ago)
Author:
chronos
Message:
  • Fixed: XML database can be opened from file.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UDatabase.pas

    r6 r7  
    1111  TTable = class;
    1212  TDatabaseEngine = class;
     13  TDatabaseClient = class;
    1314
    1415  TFieldType = (ftString, ftInteger, ftDateTime, ftBoolean, ftFloat, ftImage,
     
    107108
    108109  TDatabase = class
     110  private
     111    FEngine: TDatabaseEngine;
     112    procedure SetEngine(AValue: TDatabaseEngine);
     113  public
    109114    Name: string;
    110115    Tables: TTables;
    111116    ConnectionString: string;
    112     Engine: TDatabaseEngine;
     117    Client: TDatabaseClient;
    113118    constructor Create;
    114119    destructor Destroy; override;
    115120    procedure Load; virtual;
    116121    procedure Save; virtual;
     122    property Engine: TDatabaseEngine read FEngine write SetEngine;
    117123  end;
    118124
     
    134140  end;
    135141
     142  { TDatabaseClient }
     143
     144  TDatabaseClient = class
     145    Database: TDatabase;
     146    procedure Load; virtual;
     147    procedure Save; virtual;
     148  end;
     149
     150  TDatabaseClientClass = class of TDatabaseClient;
     151
    136152  { TDatabaseEngine }
    137153
     
    139155    Name: string;
    140156    DataTypes: TDataTypes;
    141     DatabaseClass: TDatabaseClass;
     157    DatabaseClientClass: TDatabaseClientClass;
    142158    constructor Create;
    143159    destructor Destroy; override;
     
    147163
    148164  TDatabaseEngines = class(TObjectList)
    149     function RegisterEngine(Name: string; DatabaseClass: TDatabaseClass): TDatabaseEngine;
     165    function RegisterEngine(Name: string; DatabaseClass: TDatabaseClientClass): TDatabaseEngine;
    150166    function FindByName(Name: string): TDatabaseEngine;
    151167  end;
     
    157173  UDataTypes;
    158174
     175{ TDatabaseClient }
     176
     177procedure TDatabaseClient.Load;
     178begin
     179
     180end;
     181
     182procedure TDatabaseClient.Save;
     183begin
     184
     185end;
     186
    159187{ TDatabaseEngines }
    160188
    161189function TDatabaseEngines.RegisterEngine(Name: string;
    162   DatabaseClass: TDatabaseClass): TDatabaseEngine;
     190  DatabaseClass: TDatabaseClientClass): TDatabaseEngine;
    163191begin
    164192  Result := TDatabaseEngine.Create;
    165193  Result.Name := Name;
    166   Result.DatabaseClass := DatabaseClass;
     194  Result.DatabaseClientClass := DatabaseClass;
    167195  Add(Result);
    168196end;
     
    365393{ TDatabase }
    366394
     395procedure TDatabase.SetEngine(AValue: TDatabaseEngine);
     396begin
     397  if FEngine = AValue then Exit;
     398  if Assigned(Client) then
     399    Client.Free;
     400  FEngine := AValue;
     401  if Assigned(FEngine) then begin
     402    Client := Engine.DatabaseClientClass.Create;
     403    Client.Database := Self;
     404  end;
     405end;
     406
    367407constructor TDatabase.Create;
    368408begin
    369409  Tables := TTables.Create;
     410  Engine := nil;
    370411end;
    371412
     
    378419procedure TDatabase.Load;
    379420begin
    380 
     421  if Assigned(Client) then Client.Load;
    381422end;
    382423
    383424procedure TDatabase.Save;
    384425begin
    385 
     426  if Assigned(Client) then Client.Save;
    386427end;
    387428
Note: See TracChangeset for help on using the changeset viewer.