Changeset 356
- Timestamp:
- Dec 30, 2024, 10:10:26 PM (3 days ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/ItemList.pas
r355 r356 86 86 TGetCountEvent = function: SizeInt of object; 87 87 TSetItemEvent = procedure(Index: SizeInt; AValue: TItem) of object; 88 TGetNameEvent = function: stringof object;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 = function(Name: string): stringof object;92 TGetNextAvailableNameEvent = procedure (Name: string; out NewName: string) of object; 93 93 TCreateItemEvent = function(Name: string = ''): TItem of object; 94 94 private … … 138 138 function BaseAdd(constref AValue: TItem): SizeInt; 139 139 function BaseGetCount: SizeInt; 140 function BaseGetName(A: string): string;140 procedure BaseGetName(out Name: string); 141 141 function BaseRemove(constref AValue: TItem): SizeInt; 142 142 function BaseGetItemFields: TItemFields; 143 143 function BaseCreateItem(Name: string = ''): TItem; 144 procedure BaseGetNextAvailableName(Name: string; out NewName: string); 144 145 public 145 146 NewId: Integer; 146 147 function CreateItem(Name: string = ''): T; virtual; 147 148 function IncrementName(Name: string): string; 148 function GetNextAvailableName(Name: string): string;149 149 function FindById(Id: Integer): T; 150 150 function FindByName(Name: string): T; … … 285 285 FBaseItemList.OnGetItemFields := BaseGetItemFields; 286 286 FBaseItemList.OnCreateItem := BaseCreateItem; 287 //FBaseItemList.OnGetNextAvailableName :=GetNextAvailableName;288 //FBaseItemList.OnGetName := BaseGetName;287 FBaseItemList.OnGetNextAvailableName := BaseGetNextAvailableName; 288 FBaseItemList.OnGetName := BaseGetName; 289 289 NewId := 1; 290 290 end; … … 301 301 end; 302 302 303 function TItemList<T>.BaseGetName(A: string): string;304 begin 305 Result:= T.GetClassName;303 procedure TItemList<T>.BaseGetName(out Name: string); 304 begin 305 Name := T.GetClassName; 306 306 end; 307 307 … … 364 364 end; 365 365 366 function TItemList<T>.GetNextAvailableName(Name: string): string; 367 begin 368 Result := Name; 369 while Assigned(FindByName(Result)) do 370 Result := IncrementName(Result); 366 procedure TItemList<T>.BaseGetNextAvailableName(Name: string; out 367 NewName: string); 368 begin 369 NewName := Name; 370 while Assigned(FindByName(NewName)) do 371 NewName := IncrementName(NewName); 371 372 end; 372 373 … … 757 758 begin 758 759 if Assigned(FOnSetItem) then FOnSetItem(Index, AValue) 759 else Exception.Create('Undefined SetItem handler');760 else raise Exception.Create('Undefined SetItem handler'); 760 761 end; 761 762 762 763 function TBaseItemList.GetName: string; 763 begin 764 if Assigned(FOnGetName) then Result := FOnGetName 765 else Exception.Create('Undefined GetName handler'); 764 var 765 Name: string; 766 begin 767 if Assigned(FOnGetName) then begin 768 FOnGetName(Name); 769 Result := Name; 770 end else raise Exception.Create('Undefined GetName handler'); 766 771 end; 767 772 … … 769 774 begin 770 775 if Assigned(FOnGetCount) then Result := FOnGetCount 771 else Exception.Create('Undefined GetCount handler');776 else raise Exception.Create('Undefined GetCount handler'); 772 777 end; 773 778 … … 775 780 begin 776 781 if Assigned(FOnGetItem) then Result := FOnGetItem(Index) 777 else Exception.Create('Undefined GetItem handler');782 else raise Exception.Create('Undefined GetItem handler'); 778 783 end; 779 784 … … 781 786 begin 782 787 if Assigned(FOnRemove) then Result := FOnRemove(AValue) 783 else Exception.Create('Undefined Remove handler');788 else raise Exception.Create('Undefined Remove handler'); 784 789 end; 785 790 … … 787 792 begin 788 793 if Assigned(FOnAdd) then Result := FOnAdd(AValue) 789 else Exception.Create('Undefined Add handler');794 else raise Exception.Create('Undefined Add handler'); 790 795 end; 791 796 … … 793 798 begin 794 799 if Assigned(FOnCreateItem) then Result := FOnCreateItem(Name) 795 else Exception.Create('Undefined CreateItem handler');800 else raise Exception.Create('Undefined CreateItem handler'); 796 801 end; 797 802 798 803 function TBaseItemList.GetNextAvailableName(Name: string): string; 799 begin 800 if Assigned(FOnGetNextAvailableName) then Result := FOnGetNextAvailableName(Name) 801 else Exception.Create('Undefined GetNextAvailableName handler'); 804 var 805 NewName: string; 806 begin 807 if Assigned(FOnGetNextAvailableName) then begin 808 FOnGetNextAvailableName(Name, NewName); 809 Result := NewName; 810 end else raise Exception.Create('Undefined GetNextAvailableName handler'); 802 811 end; 803 812 … … 805 814 begin 806 815 if Assigned(FOnGetItemFields) then Result := FOnGetItemFields 807 else Exception.Create('Undefined GetItemFields handler');816 else raise Exception.Create('Undefined GetItemFields handler'); 808 817 end; 809 818
Note:
See TracChangeset
for help on using the changeset viewer.