Changeset 7
- Timestamp:
- Jan 20, 2015, 11:33:39 PM (10 years ago)
- Location:
- trunk
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/DbEngines/UEngineMySQL.pas
r6 r7 9 9 10 10 type 11 TDatabaseMySQL = class(TDatabase )11 TDatabaseMySQL = class(TDatabaseClient) 12 12 13 13 end; -
trunk/DbEngines/UEngineSQLite.pas
r6 r7 9 9 10 10 type 11 TDatabaseSQLite = class(TDatabase )11 TDatabaseSQLite = class(TDatabaseClient) 12 12 13 13 end; -
trunk/DbEngines/UEngineXML.pas
r6 r7 11 11 { TDatabaseXML } 12 12 13 TDatabaseXML = class(TDatabase )13 TDatabaseXML = class(TDatabaseClient) 14 14 private 15 15 function GetFileName: string; … … 47 47 function TDatabaseXML.GetFileName: string; 48 48 begin 49 if Copy( ConnectionString, 1, 8) = 'file:///' then50 Result := Copy( ConnectionString, 8, High(Integer))49 if Copy(Database.ConnectionString, 1, 8) = 'file:///' then 50 Result := Copy(Database.ConnectionString, 8, High(Integer)) 51 51 else Result := ''; 52 52 end; … … 238 238 NewNode := FindNode('Tables'); 239 239 if Assigned(NewNode) then 240 LoadNodeTables( Tables, NewNode);240 LoadNodeTables(Database.Tables, NewNode); 241 241 end; 242 242 finally … … 259 259 NewNode := OwnerDocument.CreateElement('Tables'); 260 260 AppendChild(NewNode); 261 SaveNodeTables( Tables, NewNode);261 SaveNodeTables(Database.Tables, NewNode); 262 262 end; 263 263 ForceDirectoriesUTF8(ExtractFileDir(FileName)); … … 270 270 procedure TDatabaseXML.Load; 271 271 begin 272 inherited Load;273 272 if FileExists(FileName) then 274 273 LoadFromFile(FileName); … … 277 276 procedure TDatabaseXML.Save; 278 277 begin 279 inherited Save;280 278 SaveToFile(FileName); 281 279 end; -
trunk/Forms/UFormMain.lfm
r6 r7 5 5 Width = 1250 6 6 Caption = 'MyData' 7 ClientHeight = 820 8 ClientWidth = 1250 9 Menu = MainMenu1 7 10 OnActivate = FormActivate 8 11 OnClose = FormClose 9 12 OnShow = FormShow 10 13 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 11 47 end -
trunk/Forms/UFormMain.pas
r6 r7 6 6 7 7 uses 8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs; 8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Menus, 9 ComCtrls; 9 10 10 11 type … … 13 14 14 15 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; 15 25 procedure FormActivate(Sender: TObject); 16 26 procedure FormClose(Sender: TObject; var CloseAction: TCloseAction); -
trunk/UCore.lfm
r6 r7 1184 1184 OnExecute = AExitExecute 1185 1185 end 1186 object APreferences: TAction 1187 Caption = 'Preferences' 1188 end 1186 1189 end 1187 1190 end -
trunk/UCore.pas
r6 r7 13 13 14 14 TCore = class(TDataModule) 15 APreferences: TAction; 15 16 AExit: TAction; 16 17 ActionList1: TActionList; … … 99 100 I: Integer; 100 101 NewDatabase: TDatabase; 102 Engine: TDatabaseEngine; 101 103 begin 102 104 Databases.Count := XMLConfig1.GetValue('Database/Count', 0); 103 105 for I := 0 to Databases.Count - 1 do begin 106 Engine := Core.Engines.FindByName(XMLConfig1.GetValue('Database/Item' + IntToStr(I) + '/Engine', '')); 107 104 108 NewDatabase := TDatabase.Create; 109 NewDatabase.Engine := Engine; 105 110 NewDatabase.Name := XMLConfig1.GetValue('Database/Item' + IntToStr(I) + '/Name', ''); 106 111 NewDatabase.ConnectionString := XMLConfig1.GetValue('Database/Item' + IntToStr(I) + '/ConnectionString', ''); 107 NewDatabase.Engine := Core.Engines.FindByName(XMLConfig1.GetValue('Database/Item' + IntToStr(I) + '/Engine', ''));108 112 Databases[I] := NewDatabase; 109 113 end; -
trunk/UDatabase.pas
r6 r7 11 11 TTable = class; 12 12 TDatabaseEngine = class; 13 TDatabaseClient = class; 13 14 14 15 TFieldType = (ftString, ftInteger, ftDateTime, ftBoolean, ftFloat, ftImage, … … 107 108 108 109 TDatabase = class 110 private 111 FEngine: TDatabaseEngine; 112 procedure SetEngine(AValue: TDatabaseEngine); 113 public 109 114 Name: string; 110 115 Tables: TTables; 111 116 ConnectionString: string; 112 Engine: TDatabaseEngine;117 Client: TDatabaseClient; 113 118 constructor Create; 114 119 destructor Destroy; override; 115 120 procedure Load; virtual; 116 121 procedure Save; virtual; 122 property Engine: TDatabaseEngine read FEngine write SetEngine; 117 123 end; 118 124 … … 134 140 end; 135 141 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 136 152 { TDatabaseEngine } 137 153 … … 139 155 Name: string; 140 156 DataTypes: TDataTypes; 141 DatabaseCl ass: TDatabaseClass;157 DatabaseClientClass: TDatabaseClientClass; 142 158 constructor Create; 143 159 destructor Destroy; override; … … 147 163 148 164 TDatabaseEngines = class(TObjectList) 149 function RegisterEngine(Name: string; DatabaseClass: TDatabaseCl ass): TDatabaseEngine;165 function RegisterEngine(Name: string; DatabaseClass: TDatabaseClientClass): TDatabaseEngine; 150 166 function FindByName(Name: string): TDatabaseEngine; 151 167 end; … … 157 173 UDataTypes; 158 174 175 { TDatabaseClient } 176 177 procedure TDatabaseClient.Load; 178 begin 179 180 end; 181 182 procedure TDatabaseClient.Save; 183 begin 184 185 end; 186 159 187 { TDatabaseEngines } 160 188 161 189 function TDatabaseEngines.RegisterEngine(Name: string; 162 DatabaseClass: TDatabaseCl ass): TDatabaseEngine;190 DatabaseClass: TDatabaseClientClass): TDatabaseEngine; 163 191 begin 164 192 Result := TDatabaseEngine.Create; 165 193 Result.Name := Name; 166 Result.DatabaseCl ass := DatabaseClass;194 Result.DatabaseClientClass := DatabaseClass; 167 195 Add(Result); 168 196 end; … … 365 393 { TDatabase } 366 394 395 procedure TDatabase.SetEngine(AValue: TDatabaseEngine); 396 begin 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; 405 end; 406 367 407 constructor TDatabase.Create; 368 408 begin 369 409 Tables := TTables.Create; 410 Engine := nil; 370 411 end; 371 412 … … 378 419 procedure TDatabase.Load; 379 420 begin 380 421 if Assigned(Client) then Client.Load; 381 422 end; 382 423 383 424 procedure TDatabase.Save; 384 425 begin 385 426 if Assigned(Client) then Client.Save; 386 427 end; 387 428
Note:
See TracChangeset
for help on using the changeset viewer.