Changeset 407 for trunk/Packages/Common/ItemList.pas
- Timestamp:
- Jan 8, 2025, 10:18:12 AM (30 hours ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/ItemList.pas
r399 r407 83 83 public 84 84 type 85 TAddEvent = function 85 TAddEvent = function(constref AValue: TItem): SizeInt of object; 86 86 TGetCountEvent = function: SizeInt of object; 87 87 TSetItemEvent = procedure(Index: SizeInt; AValue: TItem) of object; 88 TGetNameEvent = procedure 88 TGetNameEvent = procedure(out Name: string) of object; 89 89 TGetItemEvent = function(Index: SizeInt): TItem of object; 90 90 TGetItemFieldsEvent = function: TItemFields of object; 91 91 TRemoveEvent = function(constref AValue: TItem): SizeInt of object; 92 TGetNextAvailableNameEvent = procedure 92 TGetNextAvailableNameEvent = procedure(Name: string; out NewName: string) of object; 93 93 TCreateItemEvent = function(Name: string = ''): TItem of object; 94 TFindByIdEvent = function(Id: Integer): TItem of object; 94 95 private 95 96 FOnAdd: TAddEvent; 96 97 FOnCreateItem: TCreateItemEvent; 98 FOnFindById: TFindByIdEvent; 97 99 FOnGetCount: TGetCountEvent; 98 100 FOnGetItem: TGetItemEvent; … … 112 114 function GetNextAvailableName(Name: string): string; 113 115 function GetItemFields: TItemFields; 116 function FindById(Id: Integer): TItem; 114 117 property Count: SizeInt read GetCount; 115 118 property Items[Index: SizeInt]: TItem read GetItem write SetItem; default; … … 125 128 property OnCreateItem: TCreateItemEvent read FOnCreateItem 126 129 write FOnCreateItem; 130 property OnFindById: TFindByIdEvent read FOnFindById 131 write FOnFindById; 127 132 end; 128 133 … … 141 146 function BaseGetItemFields: TItemFields; 142 147 function BaseCreateItem(Name: string = ''): TItem; 148 function BaseFindById(Id: Integer): TItem; 143 149 procedure BaseGetNextAvailableName(Name: string; out NewName: string); 144 150 public … … 245 251 end; 246 252 253 function TItemList<T>.BaseFindById(Id: Integer): TItem; 254 begin 255 Result := FindById(Id); 256 end; 257 247 258 procedure TItemList<T>.LoadFromNode(Node: TDOMNode); 248 259 var … … 286 297 FBaseItemList.OnGetNextAvailableName := BaseGetNextAvailableName; 287 298 FBaseItemList.OnGetName := BaseGetName; 299 FBaseItemList.OnFindById := BaseFindById; 288 300 NewId := 1; 289 301 end; … … 483 495 ReadId: Integer; 484 496 ReferenceList: TBaseItemList; 497 RefItem: TItem; 485 498 begin 486 499 if Field.DataType = dtString then begin … … 503 516 ReferenceList := GetReferenceList(Field.Index); 504 517 if (ReadId > 0) and Assigned(ReferenceList) then 505 SetValueReference(Field.Index, TItem(ReferenceList[ReadId])); 518 RefItem := ReferenceList.FindById(ReadId); 519 if Assigned(RefItem) then 520 SetValueReference(Field.Index, RefItem) 521 else raise Exception.Create('Reference id ' + IntToStr(ReadId) + ' not found.'); 506 522 end else 507 523 raise Exception.Create(Format(SUnsupportedDataType, [DataTypeStr[Field.DataType]])); … … 817 833 end; 818 834 835 function TBaseItemList.FindById(Id: Integer): TItem; 836 begin 837 if Assigned(FOnFindById) then Result := FOnFindById(Id) 838 else raise Exception.Create('Undefined FindById handler'); 839 end; 840 819 841 end. 820 842
Note:
See TracChangeset
for help on using the changeset viewer.