Changeset 296 for trunk/UItemList.pas
- Timestamp:
- Mar 29, 2019, 12:58:09 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UItemList.pas
r294 r296 9 9 10 10 type 11 TUndefinedEnum = (eeNone); 12 11 13 TDataType = (dtNone, dtString, dtBoolean, dtInteger, dtFloat, dtColor, 12 14 dtTime, dtDate, dtDateTime, dtEnumeration); … … 21 23 Position: TPoint; 22 24 Size: TPoint; 25 EnumStates: TStringList; 26 constructor Create; 27 destructor Destroy; override; 23 28 procedure Assign(Source: TItemField); 24 29 end; … … 48 53 function GetValueColor(Index: Integer): TColor; 49 54 function GetValueBoolean(Index: Integer): Boolean; 55 function GetValueEnumeration(Index: Integer): TUndefinedEnum; 50 56 function GetValueAsText(Index: Integer): string; 51 57 procedure SetValue(Index: Integer; var Value); virtual; … … 54 60 procedure SetValueColor(Index: Integer; Value: TColor); 55 61 procedure SetValueBoolean(Index: Integer; Value: Boolean); 62 procedure SetValueEnumeration(Index: Integer; Value: TUndefinedEnum); 56 63 procedure Assign(Source: TItem); virtual; 57 64 procedure LoadFromNode(Node: TDOMNode); virtual; … … 80 87 end; 81 88 89 const 90 DataTypeStr: array[TDataType] of string = ('None', 'String', 'Boolean', 91 'Integer', 'Float', 'Color', 'Time', 'Date', 'DateTime', 'Enumeration'); 92 93 resourcestring 94 SUnsupportedDataType = 'Unsupported field value data type %s'; 95 82 96 83 97 implementation … … 90 104 91 105 { TItemField } 106 107 constructor TItemField.Create; 108 begin 109 EnumStates := TStringList.Create; 110 end; 111 112 destructor TItemField.Destroy; 113 begin 114 EnumStates.Free; 115 inherited Destroy; 116 end; 92 117 93 118 procedure TItemField.Assign(Source: TItemField); … … 99 124 Position := Source.Position; 100 125 Size := Source.Size; 126 EnumStates.Assign(Source.EnumStates); 101 127 end; 102 128 … … 231 257 232 258 procedure TItem.AssignValue(Source: TItem; Field: TItemField); 233 var234 ValueString: string;235 ValueColor: TColor;236 ValueInteger: Integer;237 ValueBoolean: Boolean;238 259 begin 239 260 if Field.DataType = dtString then begin 240 Source.GetValue(Field.Index, ValueString); 241 SetValue(Field.Index, ValueString); 261 SetValueString(Field.Index, Source.GetValueString(Field.Index)); 242 262 end else 243 263 if Field.DataType = dtColor then begin 244 Source.GetValue(Field.Index, ValueColor); 245 SetValue(Field.Index, ValueColor); 264 SetValueColor(Field.Index, Source.GetValueColor(Field.Index)); 246 265 end else 247 266 if Field.DataType = dtInteger then begin 248 Source.GetValue(Field.Index, ValueInteger); 249 SetValue(Field.Index, ValueInteger); 267 SetValueInteger(Field.Index, Source.GetValueInteger(Field.Index)); 250 268 end else 251 269 if Field.DataType = dtBoolean then begin 252 Source.GetValue(Field.Index, ValueBoolean); 253 SetValue(Field.Index, ValueBoolean); 254 end else 255 raise Exception.Create('Unsupported field value data type'); 270 SetValueBoolean(Field.Index, Source.GetValueBoolean(Field.Index)); 271 end else 272 if Field.DataType = dtEnumeration then begin 273 SetValueEnumeration(Field.Index, Source.GetValueEnumeration(Field.Index)); 274 end else 275 raise Exception.Create(Format(SUnsupportedDataType, [DataTypeStr[Field.DataType]])); 256 276 end; 257 277 258 278 procedure TItem.LoadValueFromNode(Node: TDOMNode; Field: TItemField); 259 var260 ValueString: string;261 ValueColor: TColor;262 ValueInteger: Integer;263 279 begin 264 280 if Field.DataType = dtString then begin 265 ValueString := ReadString(Node, Field.SysName, ''); 266 SetValue(Field.Index, ValueString); 281 SetValueString(Field.Index, ReadString(Node, Field.SysName, '')); 267 282 end else 268 283 if Field.DataType = dtColor then begin 269 ValueColor := ReadInteger(Node, Field.SysName, 0); 270 SetValue(Field.Index, ValueColor); 284 SetValueColor(Field.Index, ReadInteger(Node, Field.SysName, 0)); 271 285 end else 272 286 if Field.DataType = dtInteger then begin 273 ValueInteger := ReadInteger(Node, Field.SysName, 0); 274 SetValue(Field.Index, ValueInteger); 275 end else 276 raise Exception.Create('Unsupported field value data type'); 287 SetValueInteger(Field.Index, ReadInteger(Node, Field.SysName, 0)); 288 end else 289 if Field.DataType = dtBoolean then begin 290 SetValueBoolean(Field.Index, ReadBoolean(Node, Field.SysName, False)); 291 end else 292 if Field.DataType = dtEnumeration then begin 293 SetValueEnumeration(Field.Index, TUndefinedEnum(ReadInteger(Node, Field.SysName, 0))); 294 end else 295 raise Exception.Create(Format(SUnsupportedDataType, [DataTypeStr[Field.DataType]])); 277 296 end; 278 297 279 298 procedure TItem.SaveValueToNode(Node: TDOMNode; Field: TItemField); 280 var281 ValueString: string;282 ValueColor: TColor;283 ValueInteger: Integer;284 299 begin 285 300 if Field.DataType = dtString then begin 286 GetValue(Field.Index, ValueString); 287 WriteString(Node, Field.SysName, ValueString); 301 WriteString(Node, Field.SysName, GetValueString(Field.Index)); 288 302 end else 289 303 if Field.DataType = dtColor then begin 290 GetValue(Field.Index, ValueColor); 291 WriteInteger(Node, Field.SysName, ValueColor); 304 WriteInteger(Node, Field.SysName, GetValueColor(Field.Index)); 292 305 end else 293 306 if Field.DataType = dtInteger then begin 294 GetValue(Field.Index, ValueInteger); 295 WriteInteger(Node, Field.SysName, ValueInteger); 296 end else 297 raise Exception.Create('Unsupported field value data type'); 307 WriteInteger(Node, Field.SysName, GetValueInteger(Field.Index)); 308 end else 309 if Field.DataType = dtBoolean then begin 310 WriteBoolean(Node, Field.SysName, GetValueBoolean(Field.Index)); 311 end else 312 if Field.DataType = dtEnumeration then begin 313 WriteInteger(Node, Field.SysName, Integer(GetValueEnumeration(Field.Index))); 314 end else 315 raise Exception.Create(Format(SUnsupportedDataType, [DataTypeStr[Field.DataType]])); 298 316 end; 299 317 … … 319 337 procedure TItem.GetValue(Index: Integer; out Value); 320 338 begin 339 raise Exception.Create('Unsupported value index ' + IntToStr(Index)); 321 340 end; 322 341 … … 341 360 end; 342 361 362 function TItem.GetValueEnumeration(Index: Integer): TUndefinedEnum; 363 begin 364 GetValue(Index, Result); 365 end; 366 343 367 function TItem.GetValueAsText(Index: Integer): string; 344 368 var 345 369 Fields: TItemFields; 346 ItemField: TItemField;370 Field: TItemField; 347 371 begin 348 372 Fields := GetFields; 349 ItemField := GetField(Fields.IndexOf(Fields.SearchByIndex(Index))); 350 if ItemField.DataType = dtInteger then Result := IntToStr(GetValueInteger(Index)) 351 else if ItemField.DataType = dtString then Result := GetValueString(Index) 352 else if ItemField.DataType = dtColor then Result := '' 353 else if ItemField.DataType = dtBoolean then begin 373 Field := GetField(Fields.IndexOf(Fields.SearchByIndex(Index))); 374 if Field.DataType = dtInteger then Result := IntToStr(GetValueInteger(Index)) 375 else if Field.DataType = dtString then Result := GetValueString(Index) 376 else if Field.DataType = dtColor then Result := '' 377 else if Field.DataType = dtEnumeration then Result := Field.EnumStates[Integer(GetValueEnumeration(Index))] 378 else if Field.DataType = dtBoolean then begin 354 379 if GetValueBoolean(Index) then Result := SYes else Result := SNo; 355 end; 356 ItemField.Free; 380 end else 381 raise Exception.Create(Format(SUnsupportedDataType, [DataTypeStr[Field.DataType]])); 382 Field.Free; 357 383 Fields.Free; 358 384 end; … … 360 386 procedure TItem.SetValue(Index: Integer; var Value); 361 387 begin 388 raise Exception.Create('Unsupported value index ' + IntToStr(Index)); 362 389 end; 363 390 … … 378 405 379 406 procedure TItem.SetValueBoolean(Index: Integer; Value: Boolean); 407 begin 408 SetValue(Index, Value); 409 end; 410 411 procedure TItem.SetValueEnumeration(Index: Integer; 412 Value: TUndefinedEnum); 380 413 begin 381 414 SetValue(Index, Value);
Note:
See TracChangeset
for help on using the changeset viewer.