Changeset 4 for trunk/UDatabase.pas
- Timestamp:
- Jan 18, 2015, 11:29:26 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UDatabase.pas
r3 r4 6 6 7 7 uses 8 Classes, SysUtils, Contnrs, ExtCtrls, StdCtrls, EditBtn ;8 Classes, SysUtils, Contnrs, ExtCtrls, StdCtrls, EditBtn, dialogs; 9 9 10 10 type 11 11 TTable = class; 12 12 13 TFieldType = (ftString, ft Numeric, ftDateTime, ftBoolean, ftFloat, ftImage,13 TFieldType = (ftString, ftInteger, ftDateTime, ftBoolean, ftFloat, ftImage, 14 14 ftDate, tfTime, ftMapPosition); 15 15 … … 17 17 18 18 TValue = class 19 procedure Assign(Source: TValue); virtual; 19 20 function GetString: string; virtual; 20 21 end; … … 22 23 TValueClass = class of TValue; 23 24 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; 25 { TValues } 41 26 42 27 TValues = class(TObjectList) 28 procedure Assign(Source: TValues); 43 29 end; 44 30 … … 46 32 47 33 TFieldTypeSpecific = class 34 procedure Assign(Source: TFieldTypeSpecific); virtual; 48 35 function GetValueClass: TValueClass; virtual; 49 36 end; 50 37 51 38 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 39 102 40 { TField } … … 117 55 Pos: TPoint; 118 56 Size: TPoint; 57 procedure Assign(Source: TField); 119 58 function GetValueClass: TValueClass; 120 59 property FieldType: TFieldType read FFieldType write SetFieldType; … … 122 61 end; 123 62 63 { TFields } 64 124 65 TFields = class(TObjectList) 66 function FindByName(Name: string): TField; 67 procedure Assign(Source: TFields); 125 68 end; 126 69 … … 130 73 Parent: TTable; 131 74 Values: TValues; 75 procedure Assign(Source: TRecord); 132 76 constructor Create; 133 77 destructor Destroy; override; 134 78 end; 135 79 80 { TRecords } 81 136 82 TRecords = class(TObjectList) 137 83 Parent: TTable; 84 procedure Assign(Source: TRecords); 138 85 end; 139 86 … … 142 89 TTable = class 143 90 Name: string; 91 Caption: string; 144 92 Records: TRecords; 145 93 Fields: TFields; 94 procedure Assign(Source: TTable); 146 95 constructor Create; 147 96 destructor Destroy; override; … … 166 115 end; 167 116 168 const169 FieldTypeString: array[TFieldType] of string = ('String', 'Numeric', 'DateTime',170 'Boolean', 'Float', 'Image', 'Date', 'Time', 'MapPosition');171 FieldTypeClass: array[TFieldType] of TFieldTypeSpecificClass = (TFieldString,172 TFieldInteger, TFieldDateTime, TFieldBoolean, TFieldFloat, TFieldImage,173 TFieldDate, TFieldTime, TFieldMapPosition);174 175 117 176 118 implementation 177 119 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); 120 uses 121 UDataTypes; 122 123 { TValues } 124 125 procedure TValues.Assign(Source: TValues); 126 var 127 I: Integer; 128 OldCount: Integer; 129 begin 130 OldCount := Count; 131 Count := Source.Count; 132 for I := OldCount to Count - 1 do 133 //ShowMessage(TValue(Source.Items[I]).ClassName); 134 Items[I] := TValueClass(TValue(Source.Items[I]).ClassType).Create; 135 for I := 0 to Count - 1 do 136 if TValue(Items[I]).ClassType <> TValue(Source.Items[I]).ClassType then begin 137 Items[I] := TValueClass(TValue(Source.Items[I]).ClassType).Create; 138 end; 139 for I := 0 to Source.Count - 1 do begin 140 TValue(Items[I]).Assign(TValue(Source.Items[I])); 141 end; 142 end; 143 144 { TRecords } 145 146 procedure TRecords.Assign(Source: TRecords); 147 var 148 I: Integer; 149 OldCount: Integer; 150 begin 151 OldCount := Count; 152 Count := Source.Count; 153 for I := OldCount to Count - 1 do 154 Items[I] := TRecord.Create; 155 for I := 0 to Source.Count - 1 do begin 156 TRecord(Items[I]).Assign(TRecord(Source.Items[I])); 157 end; 158 end; 159 160 { TFields } 161 162 function TFields.FindByName(Name: string): TField; 163 var 164 I: Integer; 165 begin 166 I := 0; 167 while (I < Count) and (TField(Items[I]).Name <> Name) do Inc(I); 168 if I < Count then Result := TField(Items[I]) 169 else Result := nil; 170 end; 171 172 procedure TFields.Assign(Source: TFields); 173 var 174 I: Integer; 175 OldCount: Integer; 176 begin 177 OldCount := Count; 178 Count := Source.Count; 179 for I := OldCount to Count - 1 do 180 Items[I] := TField.Create; 181 for I := 0 to Source.Count - 1 do begin 182 TField(Items[I]).Assign(TField(Source.Items[I])); 183 end; 190 184 end; 191 185 192 186 { TRecord } 187 188 procedure TRecord.Assign(Source: TRecord); 189 begin 190 Values.Assign(Source.Values); 191 end; 193 192 194 193 constructor TRecord.Create; … … 203 202 end; 204 203 205 { TValueString }206 207 function TValueString.GetString: string;208 begin209 Result := Value;210 end;211 212 204 { TValue } 213 205 206 procedure TValue.Assign(Source: TValue); 207 begin 208 end; 209 214 210 function TValue.GetString: string; 215 211 begin … … 217 213 end; 218 214 219 { TFieldString }220 221 function TFieldString.GetValueClass: TValueClass;222 begin223 Result := TValueString;224 end;225 226 215 { TFieldTypeSpecific } 216 217 procedure TFieldTypeSpecific.Assign(Source: TFieldTypeSpecific); 218 begin 219 220 end; 227 221 228 222 function TFieldTypeSpecific.GetValueClass: TValueClass; … … 241 235 end; 242 236 237 procedure TField.Assign(Source: TField); 238 begin 239 Name := Source.Name; 240 FieldType := Source.FieldType; 241 TextAfter := Source.TextAfter; 242 TextBefore := Source.TextBefore; 243 Required := Source.Required; 244 ReadOnly := Source.ReadOnly; 245 Description := Source.Description; 246 AllowNull := Source.AllowNull; 247 TypeRelated.Assign(Source.TypeRelated); 248 end; 249 243 250 function TField.GetValueClass: TValueClass; 244 251 begin … … 252 259 end; 253 260 254 { TField }255 256 257 261 { TTable } 262 263 procedure TTable.Assign(Source: TTable); 264 begin 265 Name := Source.Name; 266 Caption := Source.Caption; 267 Fields.Assign(Source.Fields); 268 Records.Assign(Source.Records); 269 end; 258 270 259 271 constructor TTable.Create;
Note:
See TracChangeset
for help on using the changeset viewer.