I looked to code, it gives error only when map is Sorted=True.
function TFPSMap.Add(AKey: Pointer): Integer;
begin
if Sorted then
begin
if Find(AKey, Result) then
case Duplicates of
dupIgnore: exit;
dupError: Error(SDuplicateItem, 0)
end;
end else
Result := Count;
CopyKey(AKey, inherited Insert(Result));
end;
V.
______________________________________________________________
Show quoted text 5 lines
Od: "Ryan Joseph via fpc-pascal"
Komu: "FPC-Pascal users discussions"
Datum: 02.10.2020 02:24
Předmět: [fpc-pascal] TFPGMapObject duplicate errors
I expected to get an assertion when I added the duplicate key "foo". What am I doing wrong?
type
TSomeMap = specialize TFPGMapObject<String, TObject>;
var
map: TSomeMap;
begin
map := TSomeMap.Create(true);
map.Duplicates := dupError;
map.Add('foo', TObject.Create);
map.Add('foo', TObject.Create);
Regards,
Ryan Joseph