Changeset 7 for trunk


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

Legend:

Unmodified
Added
Removed
  • trunk/DbEngines/UEngineMySQL.pas

    r6 r7  
    99
    1010type
    11   TDatabaseMySQL = class(TDatabase)
     11  TDatabaseMySQL = class(TDatabaseClient)
    1212
    1313  end;
  • trunk/DbEngines/UEngineSQLite.pas

    r6 r7  
    99
    1010type
    11   TDatabaseSQLite = class(TDatabase)
     11  TDatabaseSQLite = class(TDatabaseClient)
    1212
    1313  end;
  • trunk/DbEngines/UEngineXML.pas

    r6 r7  
    1111  { TDatabaseXML }
    1212
    13   TDatabaseXML = class(TDatabase)
     13  TDatabaseXML = class(TDatabaseClient)
    1414  private
    1515    function GetFileName: string;
     
    4747function TDatabaseXML.GetFileName: string;
    4848begin
    49   if Copy(ConnectionString, 1, 8) = 'file:///' then
    50     Result := Copy(ConnectionString, 8, High(Integer))
     49  if Copy(Database.ConnectionString, 1, 8) = 'file:///' then
     50    Result := Copy(Database.ConnectionString, 8, High(Integer))
    5151    else Result := '';
    5252end;
     
    238238      NewNode := FindNode('Tables');
    239239      if Assigned(NewNode) then
    240         LoadNodeTables(Tables, NewNode);
     240        LoadNodeTables(Database.Tables, NewNode);
    241241    end;
    242242  finally
     
    259259      NewNode := OwnerDocument.CreateElement('Tables');
    260260      AppendChild(NewNode);
    261       SaveNodeTables(Tables, NewNode);
     261      SaveNodeTables(Database.Tables, NewNode);
    262262    end;
    263263    ForceDirectoriesUTF8(ExtractFileDir(FileName));
     
    270270procedure TDatabaseXML.Load;
    271271begin
    272   inherited Load;
    273272  if FileExists(FileName) then
    274273    LoadFromFile(FileName);
     
    277276procedure TDatabaseXML.Save;
    278277begin
    279   inherited Save;
    280278  SaveToFile(FileName);
    281279end;
  • trunk/Forms/UFormMain.lfm

    r6 r7  
    55  Width = 1250
    66  Caption = 'MyData'
     7  ClientHeight = 820
     8  ClientWidth = 1250
     9  Menu = MainMenu1
    710  OnActivate = FormActivate
    811  OnClose = FormClose
    912  OnShow = FormShow
    1013  LCLVersion = '1.3'
     14  object StatusBar1: TStatusBar
     15    Left = 0
     16    Height = 29
     17    Top = 791
     18    Width = 1250
     19    Panels = <>
     20  end
     21  object MainMenu1: TMainMenu
     22    Images = Core.ImageList1
     23    left = 870
     24    top = 200
     25    object MenuItem1: TMenuItem
     26      Caption = 'Database'
     27      object MenuItem2: TMenuItem
     28        Caption = 'Connect'
     29      end
     30      object MenuItem4: TMenuItem
     31        Caption = 'Disconnect'
     32      end
     33      object MenuItem5: TMenuItem
     34        Caption = '-'
     35      end
     36      object MenuItem6: TMenuItem
     37        Action = Core.AExit
     38      end
     39    end
     40    object MenuItemPreferences: TMenuItem
     41      Caption = 'Tools'
     42      object MenuItem3: TMenuItem
     43        Action = Core.APreferences
     44      end
     45    end
     46  end
    1147end
  • trunk/Forms/UFormMain.pas

    r6 r7  
    66
    77uses
    8   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs;
     8  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Menus,
     9  ComCtrls;
    910
    1011type
     
    1314
    1415  TFormMain = class(TForm)
     16    MainMenu1: TMainMenu;
     17    MenuItem1: TMenuItem;
     18    MenuItem2: TMenuItem;
     19    MenuItem3: TMenuItem;
     20    MenuItem4: TMenuItem;
     21    MenuItem5: TMenuItem;
     22    MenuItem6: TMenuItem;
     23    MenuItemPreferences: TMenuItem;
     24    StatusBar1: TStatusBar;
    1525    procedure FormActivate(Sender: TObject);
    1626    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
  • trunk/UCore.lfm

    r6 r7  
    11841184      OnExecute = AExitExecute
    11851185    end
     1186    object APreferences: TAction
     1187      Caption = 'Preferences'
     1188    end
    11861189  end
    11871190end
  • trunk/UCore.pas

    r6 r7  
    1313
    1414  TCore = class(TDataModule)
     15    APreferences: TAction;
    1516    AExit: TAction;
    1617    ActionList1: TActionList;
     
    99100  I: Integer;
    100101  NewDatabase: TDatabase;
     102  Engine: TDatabaseEngine;
    101103begin
    102104  Databases.Count := XMLConfig1.GetValue('Database/Count', 0);
    103105  for I := 0 to Databases.Count - 1 do begin
     106    Engine := Core.Engines.FindByName(XMLConfig1.GetValue('Database/Item' + IntToStr(I) + '/Engine', ''));
     107
    104108    NewDatabase := TDatabase.Create;
     109    NewDatabase.Engine := Engine;
    105110    NewDatabase.Name := XMLConfig1.GetValue('Database/Item' + IntToStr(I) + '/Name', '');
    106111    NewDatabase.ConnectionString := XMLConfig1.GetValue('Database/Item' + IntToStr(I) + '/ConnectionString', '');
    107     NewDatabase.Engine := Core.Engines.FindByName(XMLConfig1.GetValue('Database/Item' + IntToStr(I) + '/Engine', ''));
    108112    Databases[I] := NewDatabase;
    109113  end;
  • 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.