Changeset 8 for trunk/UDatabase.pas
- Timestamp:
- Jan 23, 2015, 12:00:37 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UDatabase.pas
r7 r8 12 12 TDatabaseEngine = class; 13 13 TDatabaseClient = class; 14 TDatabase = class; 15 TDataType = class; 14 16 15 17 TFieldType = (ftString, ftInteger, ftDateTime, ftBoolean, ftFloat, ftImage, 16 ftDate, tfTime, ftMapPosition);18 ftDate, ftTime, ftMapPosition); 17 19 18 20 { TValue } … … 44 46 TField = class 45 47 private 46 F FieldType: TFieldType;47 procedure Set FieldType(AValue: TFieldType);48 FDataType: TDataType; 49 procedure SetDataType(AValue: TDataType); 48 50 public 49 51 Name: string; … … 57 59 Pos: TPoint; 58 60 Size: TPoint; 61 Table: TTable; 59 62 procedure Assign(Source: TField); 60 63 function GetValueClass: TValueClass; 61 property FieldType: TFieldType read FFieldType write SetFieldType;64 property DataType: TDataType read FDataType write SetDataType; 62 65 constructor Create; 63 66 end; … … 66 69 67 70 TFields = class(TObjectList) 71 Table: TTable; 68 72 function FindByName(Name: string): TField; 69 73 procedure Assign(Source: TFields); … … 94 98 Records: TRecords; 95 99 Fields: TFields; 100 Database: TDatabase; 96 101 procedure Assign(Source: TTable); 97 102 constructor Create; … … 100 105 101 106 TTables = class(TObjectList) 102 107 Database: TDatabase; 103 108 end; 104 109 … … 134 139 Name: string; 135 140 FieldType: TFieldType; 136 end; 141 FieldTypeClass: TFieldTypeSpecificClass; 142 end; 143 144 { TDataTypes } 137 145 138 146 TDataTypes = class(TObjectList) 139 function RegisterType(Name: string; FieldType: TFieldType): TDataType; 147 function RegisterType(Name: string; FieldType: TFieldType; FieldTypeClass: TFieldTypeSpecificClass): TDataType; 148 function FindByType(FieldType: TFieldType): TDataType; 140 149 end; 141 150 … … 150 159 TDatabaseClientClass = class of TDatabaseClient; 151 160 161 TFieldTypeSet = set of TFieldType; 162 152 163 { TDatabaseEngine } 153 164 … … 156 167 DataTypes: TDataTypes; 157 168 DatabaseClientClass: TDatabaseClientClass; 169 procedure UseTypes(ADataTypes: TDataTypes; Types: TFieldTypeSet); 158 170 constructor Create; 159 171 destructor Destroy; override; … … 208 220 { TDataTypes } 209 221 210 function TDataTypes.RegisterType(Name: string; FieldType: TFieldType): TDataType; 222 function TDataTypes.RegisterType(Name: string; FieldType: TFieldType; 223 FieldTypeClass: TFieldTypeSpecificClass): TDataType; 211 224 begin 212 225 Result := TDataType.Create; 213 226 Result.Name := Name; 214 227 Result.FieldType := FieldType; 228 Result.FieldTypeClass := FieldTypeClass; 215 229 Add(Result); 216 230 end; 217 231 232 function TDataTypes.FindByType(FieldType: TFieldType): TDataType; 233 var 234 I: Integer; 235 begin 236 I := 0; 237 while (I < Count) and (TDataType(Items[I]).FieldType <> FieldType) do Inc(I); 238 if I < Count then Result := TDataType(Items[I]) 239 else Result := nil; 240 end; 241 218 242 { TDatabaseEngine } 219 243 244 procedure TDatabaseEngine.UseTypes(ADataTypes: TDataTypes; Types: TFieldTypeSet); 245 var 246 I: TFieldType; 247 begin 248 DataTypes.Clear; 249 for I := Low(TFieldType) to High(TFieldType) do 250 if I in Types then DataTypes.Add(ADataTypes.FindByType(I)); 251 end; 252 220 253 constructor TDatabaseEngine.Create; 221 254 begin 222 255 DataTypes := TDataTypes.Create; 256 DataTypes.OwnsObjects := False; 223 257 end; 224 258 … … 335 369 { TField } 336 370 337 procedure TField.Set FieldType(AValue: TFieldType);338 begin 339 if F FieldType = AValue then Exit;371 procedure TField.SetDataType(AValue: TDataType); 372 begin 373 if FDataType = AValue then Exit; 340 374 if Assigned(TypeRelated) then TypeRelated.Free; 341 FFieldType := AValue; 342 TypeRelated := FieldTypeClass[FFieldType].Create; 375 FDataType := AValue; 376 if Assigned(AValue) then 377 TypeRelated := AValue.FieldTypeClass.Create 378 else TypeRelated := nil; 343 379 end; 344 380 … … 346 382 begin 347 383 Name := Source.Name; 348 FieldType := Source.FieldType;384 DataType := Source.DataType; 349 385 TextAfter := Source.TextAfter; 350 386 TextBefore := Source.TextBefore; … … 382 418 Records.Parent := Self; 383 419 Fields := TFields.Create; 420 Fields.Table := Self; 384 421 end; 385 422 … … 408 445 begin 409 446 Tables := TTables.Create; 447 Tables.Database := Self; 410 448 Engine := nil; 411 449 end;
Note:
See TracChangeset
for help on using the changeset viewer.