Changeset 7 for trunk/UDatabase.pas
- Timestamp:
- Jan 20, 2015, 11:33:39 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.