Changeset 9 for trunk/UCore.pas
- Timestamp:
- Jan 25, 2015, 9:41:26 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UCore.pas
r8 r9 9 9 10 10 type 11 12 11 { TCore } 13 12 14 13 TCore = class(TDataModule) 14 ADatabaseConnect: TAction; 15 ADatabaseDisconnect: TAction; 15 16 APreferences: TAction; 16 17 AExit: TAction; … … 18 19 ImageList1: TImageList; 19 20 XMLConfig1: TXMLConfig; 21 procedure ADatabaseConnectExecute(Sender: TObject); 22 procedure ADatabaseDisconnectExecute(Sender: TObject); 20 23 procedure AExitExecute(Sender: TObject); 24 procedure APreferencesExecute(Sender: TObject); 21 25 procedure DataModuleCreate(Sender: TObject); 22 26 procedure DataModuleDestroy(Sender: TObject); 23 27 private 28 FDatabase: TDatabase; 24 29 Initialized: Boolean; 25 30 procedure InitEngines; 26 31 procedure InitDataTypes; 32 procedure SetDatabase(AValue: TDatabase); 27 33 public 34 Preferences: TPreferences; 28 35 Databases: TDatabases; 29 36 Engines: TDatabaseEngines; … … 33 40 procedure Init; 34 41 procedure Done; 42 procedure UpdateInterface; 43 property Database: TDatabase read FDatabase write SetDatabase; 35 44 end; 36 45 … … 42 51 uses 43 52 UEngineXML, UEngineMySQL, UEngineSQLite, UFormTables, UFormConnect, 44 UFormDatabases, UDataTypes ;53 UFormDatabases, UDataTypes, UFormPreferences, UFormMain; 45 54 46 55 {$R *.lfm} … … 53 62 Engines := TDatabaseEngines.Create; 54 63 DataTypes := TDataTypes.Create; 64 Preferences := TPreferences.Create; 55 65 end; 56 66 … … 60 70 end; 61 71 72 procedure TCore.ADatabaseDisconnectExecute(Sender: TObject); 73 begin 74 Database := nil; 75 end; 76 77 procedure TCore.ADatabaseConnectExecute(Sender: TObject); 78 begin 79 if FormDatabases.ShowModal = mrOk then begin 80 Database := FormDatabases.SelectedDatabase; 81 end; 82 end; 83 84 procedure TCore.APreferencesExecute(Sender: TObject); 85 begin 86 FormPreferences.Load(Preferences); 87 if FormPreferences.ShowModal = mrOk then begin 88 FormPreferences.Save(Preferences); 89 end; 90 end; 91 62 92 procedure TCore.DataModuleDestroy(Sender: TObject); 63 93 begin 64 DataTypes.Free; 65 Engines.Free; 66 Databases.Free; 94 FreeAndNil(Preferences); 95 FreeAndNil(DataTypes); 96 FreeAndNil(Engines); 97 FreeAndNil(Databases); 67 98 end; 68 99 … … 98 129 end; 99 130 131 procedure TCore.SetDatabase(AValue: TDatabase); 132 begin 133 if FDatabase = AValue then Exit; 134 if Assigned(FDatabase) then begin 135 FDatabase.Clear; 136 end; 137 FDatabase := AValue; 138 if Assigned(FDatabase) then begin 139 FDatabase.Load; 140 Preferences.LastDatabaseName := FDatabase.Name; 141 end; 142 FormTables.Database := FDatabase; 143 UpdateInterface; 144 end; 145 100 146 procedure TCore.LoadConfig; 101 147 var … … 115 161 end; 116 162 //Databases.ConnectionString := XMLConfig1.GetValue('ConnectionString', 'file://' + ExtractFileDir(Application.ExeName) + '/data.xml'); 163 Preferences.RememberDatabase := XMLConfig1.GetValue('RememberDatabase', True); 164 Preferences.LastDatabaseName := XMLConfig1.GetValue('LastDatabaseName', ''); 117 165 end; 118 166 … … 127 175 XMLConfig1.SetValue('Database/Item' + IntToStr(I) + '/Engine', TDatabase(Databases[I]).Engine.Name); 128 176 end; 177 XMLConfig1.SetValue('RememberDatabase', Preferences.RememberDatabase); 178 XMLConfig1.SetValue('LastDatabaseName', Preferences.LastDatabaseName); 129 179 end; 130 180 … … 138 188 LoadConfig; 139 189 FormDatabases.ReloadList; 190 UpdateInterface; 191 if Preferences.RememberDatabase then begin 192 Database := Databases.FindByName(Preferences.LastDatabaseName); 193 end else ADatabaseConnect.Execute; 140 194 end; 141 195 end; … … 146 200 end; 147 201 202 procedure TCore.UpdateInterface; 203 begin 204 ADatabaseDisconnect.Enabled := Assigned(FormTables.Database); 205 FormMain.UpdateInterface; 206 end; 207 148 208 end. 149 209
Note:
See TracChangeset
for help on using the changeset viewer.