| @@ -82,6 +82,7 @@ type | |||||
| PListItem = ^TListItem; | PListItem = ^TListItem; | ||||
| public type | public type | ||||
| TItemEvent = procedure(aSender: TObject; const aIndex: Integer; const aItem: T) of object; | |||||
| TEnumerator = class(TObject) | TEnumerator = class(TObject) | ||||
| private | private | ||||
| fReverse: Boolean; | fReverse: Boolean; | ||||
| @@ -117,6 +118,7 @@ type | |||||
| function GetEnumerator: TEnumerator; | function GetEnumerator: TEnumerator; | ||||
| function GetReverseEnumerator: TEnumerator; | function GetReverseEnumerator: TEnumerator; | ||||
| procedure ForEach(const aEvent: TItemEvent); | |||||
| procedure Clear; | procedure Clear; | ||||
| constructor Create(const aOwnsObjects: Boolean = true); | constructor Create(const aOwnsObjects: Boolean = true); | ||||
| @@ -180,12 +182,15 @@ type | |||||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| generic TutlHashSetBase<T> = class(specialize TutlListBase<T>) | generic TutlHashSetBase<T> = class(specialize TutlListBase<T>) | ||||
| public type | public type | ||||
| THashItemEvent = procedure(aSender: TObject; const aItem: T) of object; | |||||
| IComparer = specialize IutlComparer<T>; | IComparer = specialize IutlComparer<T>; | ||||
| private | private | ||||
| fComparer: IComparer; | fComparer: IComparer; | ||||
| protected | protected | ||||
| function SearchItem(const aMin, aMax: Integer; const aItem: T; out aIndex: Integer): Integer; | function SearchItem(const aMin, aMax: Integer; const aItem: T; out aIndex: Integer): Integer; | ||||
| public | public | ||||
| procedure ForEach(const aEvent: THashItemEvent); | |||||
| constructor Create(aComparer: IComparer; const aOwnsObjects: Boolean = true); | constructor Create(aComparer: IComparer; const aOwnsObjects: Boolean = true); | ||||
| destructor Destroy; override; | destructor Destroy; override; | ||||
| end; | end; | ||||
| @@ -224,6 +229,8 @@ type | |||||
| generic TutlMapBase<TKey, TValue> = class(TObject) | generic TutlMapBase<TKey, TValue> = class(TObject) | ||||
| public type | public type | ||||
| TKeyValuePairEvent = procedure(aSender: TObject; const aKey: TKey; const aValue: TValue) of object; | |||||
| IComparer = specialize IutlComparer<TKey>; | IComparer = specialize IutlComparer<TKey>; | ||||
| TKeyValuePair = packed record | TKeyValuePair = packed record | ||||
| Key: TKey; | Key: TKey; | ||||
| @@ -316,6 +323,7 @@ type | |||||
| procedure DeleteAt(const aIndex: Integer); | procedure DeleteAt(const aIndex: Integer); | ||||
| procedure Clear; | procedure Clear; | ||||
| procedure ForEach(const aEvent: TKeyValuePairEvent); | |||||
| function GetEnumerator: TValueEnumerator; | function GetEnumerator: TValueEnumerator; | ||||
| function GetReverseEnumerator: TValueEnumerator; | function GetReverseEnumerator: TValueEnumerator; | ||||
| @@ -895,6 +903,15 @@ begin | |||||
| result := TEnumerator.Create(fList, true); | result := TEnumerator.Create(fList, true); | ||||
| end; | end; | ||||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||||
| procedure TutlListBase.ForEach(const aEvent: TItemEvent); | |||||
| var i: Integer; | |||||
| begin | |||||
| if not Assigned(aEvent) then | |||||
| for i := 0 to fList.Count-1 do | |||||
| aEvent(self, i, PListItem(fList[i])^.data); | |||||
| end; | |||||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| procedure TutlListBase.Clear; | procedure TutlListBase.Clear; | ||||
| begin | begin | ||||
| @@ -1131,6 +1148,15 @@ begin | |||||
| end; | end; | ||||
| end; | end; | ||||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||||
| procedure TutlHashSetBase.ForEach(const aEvent: THashItemEvent); | |||||
| var item: T; | |||||
| begin | |||||
| if Assigned(aEvent) then | |||||
| for item in self do | |||||
| aEvent(self, item); | |||||
| end; | |||||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| constructor TutlHashSetBase.Create(aComparer: IComparer; const aOwnsObjects: Boolean); | constructor TutlHashSetBase.Create(aComparer: IComparer; const aOwnsObjects: Boolean); | ||||
| begin | begin | ||||
| @@ -1450,6 +1476,15 @@ begin | |||||
| fHashSetRef.Clear; | fHashSetRef.Clear; | ||||
| end; | end; | ||||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||||
| procedure TutlMapBase.ForEach(const aEvent: TKeyValuePairEvent); | |||||
| var kvp: TKeyValuePair; | |||||
| begin | |||||
| if Assigned(aEvent) then | |||||
| for kvp in fHashSetRef do | |||||
| aEvent(self, kvp.Key, kvp.Value); | |||||
| end; | |||||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| function TutlMapBase.GetEnumerator: TValueEnumerator; | function TutlMapBase.GetEnumerator: TValueEnumerator; | ||||
| begin | begin | ||||
| @@ -1747,7 +1782,8 @@ class function TutlEnumHelper.TryToEnum(aStr: String; out aValue: T): Boolean; | |||||
| var | var | ||||
| a: T; | a: T; | ||||
| begin | begin | ||||
| Result:= false; | |||||
| a := T(0); | |||||
| Result := false; | |||||
| if Length(aStr) = 0 then | if Length(aStr) = 0 then | ||||
| exit; | exit; | ||||
| @@ -1757,7 +1793,7 @@ begin | |||||
| Result:= IOResult <> 106; | Result:= IOResult <> 106; | ||||
| {$Pop} | {$Pop} | ||||
| if Result then | if Result then | ||||
| aValue:= a; | |||||
| aValue := a; | |||||
| end; | end; | ||||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| @@ -28,8 +28,7 @@ type | |||||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| generic TutlObservableCustomList<T> = class(specialize TutlCustomList<T>) | generic TutlObservableCustomList<T> = class(specialize TutlCustomList<T>) | ||||
| public type | public type | ||||
| TEvent = procedure(aSender: TObject; const aIndex: Integer; const aItem: T) of object; | |||||
| TEventList = specialize TutlEventList<TEvent>; | |||||
| TEventList = specialize TutlEventList<TItemEvent>; | |||||
| private | private | ||||
| fOnAddItem: TEventList; | fOnAddItem: TEventList; | ||||
| fOnRemoveItem: TEventList; | fOnRemoveItem: TEventList; | ||||
| @@ -55,8 +54,7 @@ type | |||||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| generic TutlObservableCustomHashSet<T> = class(specialize TutlCustomHashSet<T>) | generic TutlObservableCustomHashSet<T> = class(specialize TutlCustomHashSet<T>) | ||||
| public type | public type | ||||
| TEvent = procedure(aSender: TObject; const aItem: T) of object; | |||||
| TEventList = specialize TutlEventList<TEvent>; | |||||
| TEventList = specialize TutlEventList<THashItemEvent>; | |||||
| private | private | ||||
| fOnAddItem: TEventList; | fOnAddItem: TEventList; | ||||
| fOnRemoveItem: TEventList; | fOnRemoveItem: TEventList; | ||||
| @@ -82,8 +80,7 @@ type | |||||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| generic TutlObservableCustomMap<TKey, TValue> = class(specialize TutlMapBase<TKey, TValue>) | generic TutlObservableCustomMap<TKey, TValue> = class(specialize TutlMapBase<TKey, TValue>) | ||||
| public type | public type | ||||
| TEvent = procedure(aSender: TObject; const aKey: TKey; const aValue: TValue) of object; | |||||
| TEventList = specialize TutlEventList<TEvent>; | |||||
| TEventList = specialize TutlEventList<TKeyValuePairEvent>; | |||||
| TObservableHashSet = class(THashSet) | TObservableHashSet = class(THashSet) | ||||
| private | private | ||||
| fOwner: TObject; | fOwner: TObject; | ||||
| @@ -173,7 +170,7 @@ end; | |||||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| procedure TutlObservableCustomList.InsertIntern(const aIndex: Integer; const aItem: T); | procedure TutlObservableCustomList.InsertIntern(const aIndex: Integer; const aItem: T); | ||||
| var | var | ||||
| e: TEvent; | |||||
| e: TItemEvent; | |||||
| begin | begin | ||||
| inherited InsertIntern(aIndex, aItem); | inherited InsertIntern(aIndex, aItem); | ||||
| if Assigned(fOnAddItem) then | if Assigned(fOnAddItem) then | ||||
| @@ -184,7 +181,7 @@ end; | |||||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| procedure TutlObservableCustomList.DeleteIntern(const aIndex: Integer; const aFreeItem: Boolean); | procedure TutlObservableCustomList.DeleteIntern(const aIndex: Integer; const aFreeItem: Boolean); | ||||
| var | var | ||||
| e: TEvent; | |||||
| e: TItemEvent; | |||||
| begin | begin | ||||
| if Assigned(fOnRemoveItem) then | if Assigned(fOnRemoveItem) then | ||||
| for e in fOnRemoveItem do | for e in fOnRemoveItem do | ||||
| @@ -221,7 +218,7 @@ end; | |||||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| procedure TutlObservableCustomHashSet.InsertIntern(const aIndex: Integer; const aItem: T); | procedure TutlObservableCustomHashSet.InsertIntern(const aIndex: Integer; const aItem: T); | ||||
| var | var | ||||
| e: TEvent; | |||||
| e: THashItemEvent; | |||||
| begin | begin | ||||
| inherited InsertIntern(aIndex, aItem); | inherited InsertIntern(aIndex, aItem); | ||||
| if Assigned(fOnAddItem) then | if Assigned(fOnAddItem) then | ||||
| @@ -232,7 +229,7 @@ end; | |||||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| procedure TutlObservableCustomHashSet.DeleteIntern(const aIndex: Integer; const aFreeItem: Boolean); | procedure TutlObservableCustomHashSet.DeleteIntern(const aIndex: Integer; const aFreeItem: Boolean); | ||||
| var | var | ||||
| e: TEvent; | |||||
| e: THashItemEvent; | |||||
| begin | begin | ||||
| if Assigned(fOnRemoveItem) then | if Assigned(fOnRemoveItem) then | ||||
| for e in fOnRemoveItem do | for e in fOnRemoveItem do | ||||
| @@ -269,7 +266,7 @@ end; | |||||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| procedure TutlObservableCustomMap.TObservableHashSet.InsertIntern(const aIndex: Integer; const aItem: TKeyValuePair); | procedure TutlObservableCustomMap.TObservableHashSet.InsertIntern(const aIndex: Integer; const aItem: TKeyValuePair); | ||||
| var | var | ||||
| e: TEvent; | |||||
| e: TKeyValuePairEvent; | |||||
| begin | begin | ||||
| inherited InsertIntern(aIndex, aItem); | inherited InsertIntern(aIndex, aItem); | ||||
| if Assigned(fOnAddItem) then begin | if Assigned(fOnAddItem) then begin | ||||
| @@ -281,7 +278,7 @@ end; | |||||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| procedure TutlObservableCustomMap.TObservableHashSet.DeleteIntern(const aIndex: Integer; const aFreeItem: Boolean); | procedure TutlObservableCustomMap.TObservableHashSet.DeleteIntern(const aIndex: Integer; const aFreeItem: Boolean); | ||||
| var | var | ||||
| e: TEvent; | |||||
| e: TKeyValuePairEvent; | |||||
| tmp: TKeyValuePair; | tmp: TKeyValuePair; | ||||
| begin | begin | ||||
| if Assigned(fOnRemoveItem) then begin | if Assigned(fOnRemoveItem) then begin | ||||