Changeset 342 for trunk/ItemList.pas
- Timestamp:
- Dec 22, 2024, 10:52:26 AM (10 hours ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ItemList.pas
r336 r342 41 41 private 42 42 procedure AssignValue(Source: TItem; Field: TItemField); 43 function CompareValue(Item: TItem; Field: TItemField): Boolean; 43 44 procedure LoadValueFromNode(Node: TDOMNode; Field: TItemField); virtual; 44 45 procedure SaveValueToNode(Node: TDOMNode; Field: TItemField); virtual; … … 64 65 procedure SetValueReference(Index: Integer; Value: TItem); 65 66 procedure Assign(Source: TItem); virtual; 67 function Compare(Item: TItem): Boolean; virtual; 68 function ToString: string; override; 66 69 procedure LoadFromNode(Node: TDOMNode); virtual; 67 70 procedure SaveToNode(Node: TDOMNode); virtual; … … 88 91 function FindByName(Name: string): TItem; 89 92 function GetNewId: Integer; 93 function ToString: string; override; 90 94 procedure Assign(Source: TItemList); virtual; 95 function Compare(ItemList: TItemList): Boolean; virtual; 91 96 function AddItem(Name: string = ''): TItem; virtual; 92 97 function CreateItem(Name: string = ''): TItem; virtual; … … 150 155 end; 151 156 157 function TItemList.Compare(ItemList: TItemList): Boolean; 158 var 159 I: Integer; 160 begin 161 Result := Count = ItemList.Count; 162 if not Result then Exit; 163 for I := 0 to Count - 1 do begin 164 Result := Result and TItem(Items[I]).Compare(ItemList.Items[I]); 165 if not Result then Break; 166 end; 167 end; 168 152 169 function TItemList.AddItem(Name: string): TItem; 153 170 begin … … 269 286 end; 270 287 288 function TItemList.ToString: string; 289 var 290 I: Integer; 291 begin 292 Result := ''; 293 for I := 0 to Count - 1 do 294 with TItem(Items[I]) do begin 295 Result := Result + ToString + LineEnding; 296 end; 297 end; 298 271 299 { TItemFields } 272 300 … … 312 340 if Field.DataType = dtReference then begin 313 341 SetValueReference(Field.Index, Source.GetValueReference(Field.Index)); 342 end else 343 raise Exception.Create(Format(SUnsupportedDataType, [DataTypeStr[Field.DataType]])); 344 end; 345 346 function TItem.CompareValue(Item: TItem; Field: TItemField): Boolean; 347 begin 348 if Field.DataType = dtString then begin 349 Result := GetValueString(Field.Index) = Item.GetValueString(Field.Index); 350 end else 351 if Field.DataType = dtColor then begin 352 Result := GetValueColor(Field.Index) = Item.GetValueColor(Field.Index); 353 end else 354 if Field.DataType = dtInteger then begin 355 Result := GetValueInteger(Field.Index) = Item.GetValueInteger(Field.Index); 356 end else 357 if Field.DataType = dtBoolean then begin 358 Result := GetValueBoolean(Field.Index) = Item.GetValueBoolean(Field.Index); 359 end else 360 if Field.DataType = dtEnumeration then begin 361 Result := GetValueEnumeration(Field.Index) = Item.GetValueEnumeration(Field.Index); 362 end else 363 if Field.DataType = dtReference then begin 364 Result := GetValueReference(Field.Index) = Item.GetValueReference(Field.Index); 314 365 end else 315 366 raise Exception.Create(Format(SUnsupportedDataType, [DataTypeStr[Field.DataType]])); … … 503 554 end; 504 555 556 function TItem.Compare(Item: TItem): Boolean; 557 var 558 I: Integer; 559 Fields: TItemFields; 560 begin 561 Result := True; 562 Result := Result and (Id = Item.Id); 563 if Item is ClassType then begin 564 Fields := GetFields; 565 try 566 for I := 0 to Fields.Count - 1 do begin 567 Result := Result and CompareValue(Item, Fields[I]); 568 if not Result then Break; 569 end; 570 finally 571 Fields.Free; 572 end; 573 end; 574 end; 575 576 function TItem.ToString: string; 577 var 578 Fields: TItemFields; 579 I: Integer; 580 begin 581 Result := 'Id: ' + IntToStr(Id) + LineEnding; 582 Fields := GetFields; 583 try 584 for I := 0 to Fields.Count - 1 do begin 585 Result := Result + Fields[I].SysName + ': ' + GetValueAsText(Fields[I].Index) + LineEnding; 586 end; 587 finally 588 Fields.Free; 589 end; 590 end; 591 505 592 procedure TItem.LoadFromNode(Node: TDOMNode); 506 593 var
Note:
See TracChangeset
for help on using the changeset viewer.