[fpc-pascal] TFPGMapObject duplicate errors

Vojtěch Čihák vojtech.cihak at atlas.cz
Fri Oct 2 03:00:48 CEST 2020


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.
______________________________________________________________
> Od: "Ryan Joseph via fpc-pascal" <fpc-pascal at lists.freepascal.org>
> Komu: "FPC-Pascal users discussions" <fpc-pascal at lists.freepascal.org>
> 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
 
 _______________________________________________
 fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
 https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal <https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20201002/ff833b0c/attachment.htm>


More information about the fpc-pascal mailing list