Changeset 6 for trunk/UCore.pas
- Timestamp:
- Jan 20, 2015, 12:31:24 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UCore.pas
r3 r6 22 22 private 23 23 Initialized: Boolean; 24 procedure InitEngines; 24 25 public 25 Database: TDatabase; 26 Databases: TDatabases; 27 Engines: TDatabaseEngines; 26 28 procedure LoadConfig; 27 29 procedure SaveConfig; … … 36 38 37 39 uses 38 U DatabaseXML, UFormTables;40 UEngineXML, UEngineMySQL, UEngineSQLite, UFormTables, UFormConnect, UFormDatabases; 39 41 40 42 {$R *.lfm} … … 44 46 procedure TCore.DataModuleCreate(Sender: TObject); 45 47 begin 46 Database := TDatabaseXML.Create; 48 Databases := TDatabases.Create; 49 Engines := TDatabaseEngines.Create; 47 50 end; 48 51 49 52 procedure TCore.AExitExecute(Sender: TObject); 50 53 begin 51 Form Main.Close;54 FormTables.Close; 52 55 end; 53 56 54 57 procedure TCore.DataModuleDestroy(Sender: TObject); 55 58 begin 56 Database.Free; 59 Engines.Free; 60 Databases.Free; 61 end; 62 63 procedure TCore.InitEngines; 64 var 65 NewEngine: TDatabaseEngine; 66 begin 67 Engines.Clear; 68 69 NewEngine := Engines.RegisterEngine('XML file', TDatabaseXML); 70 with NewEngine.DataTypes do begin 71 RegisterType('String', ftString); 72 RegisterType('Integer', ftInteger); 73 RegisterType('Date and time', ftDateTime); 74 RegisterType('Boolean', ftBoolean); 75 RegisterType('Float', ftFloat); 76 end; 77 78 NewEngine := Engines.RegisterEngine('MySQL', TDatabaseMySQL); 79 with NewEngine.DataTypes do begin 80 RegisterType('String', ftString); 81 RegisterType('Integer', ftInteger); 82 RegisterType('Date and time', ftDateTime); 83 RegisterType('Boolean', ftBoolean); 84 RegisterType('Float', ftFloat); 85 end; 86 87 NewEngine := Engines.RegisterEngine('SQLite', TDatabaseSQLite); 88 with NewEngine.DataTypes do begin 89 RegisterType('String', ftString); 90 RegisterType('Integer', ftInteger); 91 RegisterType('Date and time', ftDateTime); 92 RegisterType('Boolean', ftBoolean); 93 RegisterType('Float', ftFloat); 94 end; 57 95 end; 58 96 59 97 procedure TCore.LoadConfig; 98 var 99 I: Integer; 100 NewDatabase: TDatabase; 60 101 begin 61 Database.ConnectionString := XMLConfig1.GetValue('ConnectionString', 'file://' + ExtractFileDir(Application.ExeName) + '/data.xml'); 102 Databases.Count := XMLConfig1.GetValue('Database/Count', 0); 103 for I := 0 to Databases.Count - 1 do begin 104 NewDatabase := TDatabase.Create; 105 NewDatabase.Name := XMLConfig1.GetValue('Database/Item' + IntToStr(I) + '/Name', ''); 106 NewDatabase.ConnectionString := XMLConfig1.GetValue('Database/Item' + IntToStr(I) + '/ConnectionString', ''); 107 NewDatabase.Engine := Core.Engines.FindByName(XMLConfig1.GetValue('Database/Item' + IntToStr(I) + '/Engine', '')); 108 Databases[I] := NewDatabase; 109 end; 110 //Databases.ConnectionString := XMLConfig1.GetValue('ConnectionString', 'file://' + ExtractFileDir(Application.ExeName) + '/data.xml'); 62 111 end; 63 112 64 113 procedure TCore.SaveConfig; 114 var 115 I: Integer; 65 116 begin 66 XMLConfig1.SetValue('ConnectionString', Database.ConnectionString); 117 XMLConfig1.SetValue('Database/Count', Databases.Count); 118 for I := 0 to Databases.Count - 1 do begin 119 XMLConfig1.SetValue('Database/Item' + IntToStr(I) + '/Name', TDatabase(Databases[I]).Name); 120 XMLConfig1.SetValue('Database/Item' + IntToStr(I) + '/ConnectionString', TDatabase(Databases[I]).ConnectionString); 121 XMLConfig1.SetValue('Database/Item' + IntToStr(I) + '/Engine', TDatabase(Databases[I]).Engine.Name); 122 end; 67 123 end; 68 124 … … 70 126 begin 71 127 if not Initialized then begin 128 InitEngines; 129 FormConnect.Init; 72 130 Initialized := True; 73 131 LoadConfig; 74 Database.Load; 75 FormMain.ReloadList; 132 FormDatabases.ReloadList; 76 133 end; 77 134 end; … … 79 136 procedure TCore.Done; 80 137 begin 81 Database.Save;82 138 SaveConfig; 83 139 end;
Note:
See TracChangeset
for help on using the changeset viewer.