Changeset 3 for trunk/UDatabase.pas
- Timestamp:
- Jan 18, 2015, 5:25:37 PM (10 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:ignore
-
old new 3 3 MyData.lps 4 4 data.xml 5 Config.xml
-
- Property svn:ignore
-
trunk/UDatabase.pas
r2 r3 6 6 7 7 uses 8 Classes, SysUtils, Contnrs ;8 Classes, SysUtils, Contnrs, ExtCtrls, StdCtrls, EditBtn; 9 9 10 10 type 11 TTable = class; 12 11 13 TFieldType = (ftString, ftNumeric, ftDateTime, ftBoolean, ftFloat, ftImage, 12 14 ftDate, tfTime, ftMapPosition); 13 15 16 { TValue } 17 18 TValue = class 19 function GetString: string; virtual; 20 end; 21 22 TValueClass = class of TValue; 23 24 { TValueString } 25 26 TValueString = class(TValue) 27 Value: string; 28 function GetString: string; override; 29 end; 30 31 TValueInteger = class(TValue) 32 Value: Integer; 33 end; 34 35 { TValueDateTime } 36 37 TValueDateTime = class(TValue) 38 Value: TDateTime; 39 function GetString: string; override; 40 end; 41 42 TValues = class(TObjectList) 43 end; 44 45 { TFieldTypeSpecific } 46 47 TFieldTypeSpecific = class 48 function GetValueClass: TValueClass; virtual; 49 end; 50 51 TFieldTypeSpecificClass = class of TFieldTypeSpecific; 52 53 { TFieldString } 54 55 TFieldString = class(TFieldTypeSpecific) 56 DefaultValue: string; 57 function GetValueClass: TValueClass; override; 58 end; 59 60 TFieldInteger = class(TFieldTypeSpecific) 61 Min: Integer; 62 Max: Integer; 63 DefaultValue: Integer; 64 end; 65 66 TFieldFloat = class(TFieldTypeSpecific) 67 Min: Double; 68 Max: Double; 69 DefaultValue: Double; 70 end; 71 72 { TFieldDateTime } 73 74 TFieldDateTime = class(TFieldTypeSpecific) 75 Min: TDateTime; 76 Max: TDateTime; 77 function GetValueClass: TValueClass; override; 78 end; 79 80 TFieldDate = class(TFieldTypeSpecific) 81 Min: TDate; 82 Max: TDate; 83 end; 84 85 TFieldTime = class(TFieldTypeSpecific) 86 Min: TTime; 87 Max: TTime; 88 end; 89 90 TFieldImage = class(TFieldTypeSpecific) 91 MinSize: TPoint; 92 MaxSize: TPoint; 93 end; 94 95 TFieldBoolean = class(TFieldTypeSpecific) 96 DefaultValue: Boolean; 97 end; 98 99 TFieldMapPosition = class(TFieldTypeSpecific) 100 end; 101 14 102 { TField } 15 103 16 104 TField = class 105 private 106 FFieldType: TFieldType; 107 procedure SetFieldType(AValue: TFieldType); 108 public 17 109 Name: string; 18 FieldType: TFieldType;110 TypeRelated: TFieldTypeSpecific; 19 111 Required: Boolean; 20 112 ReadOnly: Boolean; … … 25 117 Pos: TPoint; 26 118 Size: TPoint; 27 end; 28 29 TFieldString = class(TField) 30 DefaultValue: string; 31 end; 32 33 TFieldInteger = class(TField) 34 Min: Integer; 35 Max: Integer; 36 DefaultValue: Integer; 37 end; 38 39 TFieldDateTime = class(TField) 40 Min: TDateTime; 41 Max: TDateTime; 42 end; 43 44 TFieldImage = class(TField) 119 function GetValueClass: TValueClass; 120 property FieldType: TFieldType read FFieldType write SetFieldType; 121 constructor Create; 45 122 end; 46 123 … … 48 125 end; 49 126 50 TValue = class 51 end; 52 53 TValueString = class 54 Value: string; 55 end; 56 57 TValueInteger = class 58 Value: Integer; 59 end; 60 61 TValueDateTime = class 62 Value: TDateTime; 63 end; 64 65 TValues = class(TObjectList) 66 end; 127 { TRecord } 67 128 68 129 TRecord = class 130 Parent: TTable; 69 131 Values: TValues; 132 constructor Create; 133 destructor Destroy; override; 70 134 end; 71 135 72 136 TRecords = class(TObjectList) 73 137 Parent: TTable; 74 138 end; 75 139 … … 105 169 FieldTypeString: array[TFieldType] of string = ('String', 'Numeric', 'DateTime', 106 170 'Boolean', 'Float', 'Image', 'Date', 'Time', 'MapPosition'); 171 FieldTypeClass: array[TFieldType] of TFieldTypeSpecificClass = (TFieldString, 172 TFieldInteger, TFieldDateTime, TFieldBoolean, TFieldFloat, TFieldImage, 173 TFieldDate, TFieldTime, TFieldMapPosition); 107 174 108 175 109 176 implementation 110 177 178 { TFieldDateTime } 179 180 function TFieldDateTime.GetValueClass: TValueClass; 181 begin 182 Result := TValueDateTime; 183 end; 184 185 { TValueDateTime } 186 187 function TValueDateTime.GetString: string; 188 begin 189 Result := DateTimeToStr(Value); 190 end; 191 192 { TRecord } 193 194 constructor TRecord.Create; 195 begin 196 Values := TValues.Create; 197 end; 198 199 destructor TRecord.Destroy; 200 begin 201 Values.Free; 202 inherited Destroy; 203 end; 204 205 { TValueString } 206 207 function TValueString.GetString: string; 208 begin 209 Result := Value; 210 end; 211 212 { TValue } 213 214 function TValue.GetString: string; 215 begin 216 Result := ''; 217 end; 218 219 { TFieldString } 220 221 function TFieldString.GetValueClass: TValueClass; 222 begin 223 Result := TValueString; 224 end; 225 226 { TFieldTypeSpecific } 227 228 function TFieldTypeSpecific.GetValueClass: TValueClass; 229 begin 230 Result := TValue; 231 end; 232 111 233 { TField } 112 234 235 procedure TField.SetFieldType(AValue: TFieldType); 236 begin 237 if FFieldType = AValue then Exit; 238 if Assigned(TypeRelated) then TypeRelated.Free; 239 FFieldType := AValue; 240 TypeRelated := FieldTypeClass[FFieldType].Create; 241 end; 242 243 function TField.GetValueClass: TValueClass; 244 begin 245 if Assigned(TypeRelated) then Result := TypeRelated.GetValueClass 246 else Result := TValue; 247 end; 248 249 constructor TField.Create; 250 begin 251 TypeRelated := TFieldString.Create; 252 end; 253 254 { TField } 255 113 256 114 257 { TTable } … … 117 260 begin 118 261 Records := TRecords.Create; 262 Records.Parent := Self; 119 263 Fields := TFields.Create; 120 264 end;
Note:
See TracChangeset
for help on using the changeset viewer.