| @@ -299,6 +299,7 @@ type | |||||
| end; | end; | ||||
| private | private | ||||
| fAutoCreate: Boolean; | |||||
| fHashSetRef: THashSet; | fHashSetRef: THashSet; | ||||
| fKeyWrapper: TKeyWrapper; | fKeyWrapper: TKeyWrapper; | ||||
| fKeyValuePairWrapper: TKeyValuePairWrapper; | fKeyValuePairWrapper: TKeyValuePairWrapper; | ||||
| @@ -315,6 +316,7 @@ type | |||||
| property Keys: TKeyWrapper read fKeyWrapper; | property Keys: TKeyWrapper read fKeyWrapper; | ||||
| property KeyValuePairs: TKeyValuePairWrapper read fKeyValuePairWrapper; | property KeyValuePairs: TKeyValuePairWrapper read fKeyValuePairWrapper; | ||||
| property Count: Integer read GetCount; | property Count: Integer read GetCount; | ||||
| property AutoCreate: Boolean read fAutoCreate write fAutoCreate; | |||||
| procedure Add(const aKey: TKey; const aValue: TValue); | procedure Add(const aKey: TKey; const aValue: TValue); | ||||
| function IndexOf(const aKey: TKey): Integer; | function IndexOf(const aKey: TKey): Integer; | ||||
| @@ -1410,9 +1412,12 @@ begin | |||||
| kvp.Key := aKey; | kvp.Key := aKey; | ||||
| kvp.Value := aValue; | kvp.Value := aValue; | ||||
| i := fHashSetRef.IndexOf(kvp); | i := fHashSetRef.IndexOf(kvp); | ||||
| if (i < 0) then | |||||
| raise EutlMap.Create('key not found'); | |||||
| fHashSetRef[i] := kvp; | |||||
| if (i < 0) then begin | |||||
| if not fAutoCreate then | |||||
| raise EutlMap.Create('key not found'); | |||||
| fHashSetRef.Add(kvp); | |||||
| end else | |||||
| fHashSetRef[i] := kvp; | |||||
| end; | end; | ||||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| @@ -1501,6 +1506,7 @@ end; | |||||
| constructor TutlMapBase.Create(const aHashSet: THashSet); | constructor TutlMapBase.Create(const aHashSet: THashSet); | ||||
| begin | begin | ||||
| inherited Create; | inherited Create; | ||||
| fAutoCreate := false; | |||||
| fHashSetRef := aHashSet; | fHashSetRef := aHashSet; | ||||
| fKeyWrapper := TKeyWrapper.Create(fHashSetRef); | fKeyWrapper := TKeyWrapper.Create(fHashSetRef); | ||||
| fKeyValuePairWrapper := TKeyValuePairWrapper.Create(fHashSetRef); | fKeyValuePairWrapper := TKeyValuePairWrapper.Create(fHashSetRef); | ||||