Forum > Packages and Libraries

Generics.Collections TDictionary issue

(1/3) > >>

JdeHaan:
Hi, I'm experiencing some inconsistencies with TDictionary. If I run the below program I would expect all written values to be TRUE but I get 1 FALSE. The result is both in ObjFpc and Delphi modes with ShortString as the key.


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program dictionary; {$mode delphi} uses Generics.Collections; var  Map: TDictionary<ShortString, Integer>;  s: ShortString; begin  Map := TDictionary<ShortString, Integer>.Create;  Map.Add('one', 1);  Map.Add('two', 2);  Map.Add('three', 3);  Map.Add('four', 4);  Map.Add('five', 5);  Map.Add('six', 6);  Map.Add('seven', 7);  Map.Add('eight', 8);   for s in Map.Keys do    writeln(s);   writeln('one:   ', Map.ContainsKey('one'));  writeln('two:   ', Map.ContainsKey('two'));  writeln('three: ', Map.ContainsKey('three')); // <-- returns FALSE  writeln('four:  ', Map.ContainsKey('four'));  writeln('five:  ', Map.ContainsKey('five'));  writeln('six:   ', Map.ContainsKey('six'));  writeln('seven: ', Map.ContainsKey('seven'));  writeln('eight: ', Map.ContainsKey('eight'));   Map.Free;end. 
Can anyone confirm this? Or has an explanation for this behaviour ?


MacOS Ventura 13.2
Lazarus 2.3.0 (rev main-2_3-3328-g448bb20ba6) FPC 3.3.1 x86_64-darwin-cocoa

TRon:
perhaps typo somewhere ?


--- Code: ---./dictionary
two
five
six
seven
one
eight
three
four
one:   TRUE
two:   TRUE
three: TRUE
four:  TRUE
five:  TRUE
six:   TRUE
seven: TRUE
eight: TRUE


--- End code ---

JdeHaan:
I used the program as is, so no typo's...

What OS are you using?

TRon:
Linux Debian bookwork (rolling) x86-64 bit. FPC 3.2.2 & 3.3.1.

make sure to do a rebuild: e.g. fpc -B dictionary.pas

edit: adjusted answer as I've just checked with fresh compiled trunk as well.

dseligo:
Works fine with Lazarus 2.2.4 and Windows 11.

Navigation

[0] Message Index

[#] Next page

Go to full version