Generics.Collections lazarus / 62-General ---------------------------------------------------------------------- Vaytl · 2022-01-10 21:45 Hi. I am trying to migrate a project from Delphi to Lazarus. I came across a generic, and I can't understand how it works at all. Is there some way to replace this code to opt out of "Generics.Collections"? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i private class var Dictionary: TDictionary;....................if not TMyprogramm.Dictionary.TryGetValue(Context, LBool)  then exit;....................Dictionary.TryAdd(DWORD_PTR(fContext), True);....................      initialization  TMyprogramm.Dictionary := TDictionary.create; ---------------------------------------------------------------------- marcov · 2022-01-10 21:53 It should work, but DWORD_PTR is a Windows specific type. Are you compiling on Windows, and what is your exact errormessage? ---------------------------------------------------------------------- Vaytl · 2022-01-10 22:01 Quote from: marcov on January 10, 2022, 10:53:53 pmAre you compiling on Windows, and what is your exact errormessage? Yes, I compiling on windows. Error: identifier idents no member "tryAdd" ---------------------------------------------------------------------- Remy Lebeau · 2022-01-11 00:09 Quote from: Vaytl on January 10, 2022, 11:01:33 pmError: identifier idents no member "tryAdd" FPC's TDictionary does not have a TryAdd() method.  Delphi's TDictionary has had TryAdd() for only a few years (since 10.3 Rio), so likely hasn't made its way into FPC yet. ---------------------------------------------------------------------- PascalDragon · 2022-01-11 08:43 Quote from: Remy Lebeau on January 11, 2022, 01:09:07 amQuote from: Vaytl on January 10, 2022, 11:01:33 pmError: identifier idents no member "tryAdd" FPC's TDictionary does not have a TryAdd() method.  Delphi's TDictionary has had TryAdd() for only a few years (since 10.3 Rio), so likely hasn't made its way into FPC yet. Would someone please report a bug so that it's not forgotten? ---------------------------------------------------------------------- Thaddy · 2022-01-11 09:04 TryAdd IS available through TOpenAddressing, which is an abstract ancestor  of TDictionary. See line 265 in generics.dictionariesh.inc The implementation is on line 610 of generics.dictionaries.inc Note TryAdd is public, so it is not hidden. So I can't explain Error: identifier idents no member "tryAdd" ---------------------------------------------------------------------- PascalDragon · 2022-01-11 09:14 Quote from: Thaddy on January 11, 2022, 10:04:53 amTryAdd IS available through TOpenAddressing, which is an abstractancestor  of TDictionary. See line 265 in generics.dictionariesh.inc The implementation is on line 610 of generics.dictionaries.inc Indeed, it should be available since 3.2.2, considering I committed that myself. @Vaytl: what version of FPC/Lazarus are you using? ---------------------------------------------------------------------- Vaytl · 2022-01-11 16:20 Quote from: PascalDragon on January 11, 2022, 10:14:22 am@Vaytl: what version of FPC/Lazarus are you using? Lazarus IDE v2.2.0RC1 r65419 X64 FPC: 3.2.2 ---------------------------------------------------------------------- bytebites · 2022-01-11 19:54 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program Project1;{$mode delphi}uses Generics.Collections;var d:TDictionary;    i:byte;begin  d:=TDictionary.create;  d.tryadd(3,4);  if d.trygetvalue(3,i) then writeln(i);  d.free;end.         This compiles with FPC 3.2.2 ---------------------------------------------------------------------- Thaddy · 2022-01-11 21:07 Quote from: Vaytl on January 11, 2022, 05:20:03 pmLazarus IDE v2.2.0RC1 r65419 X64 FPC: 3.2.2 Think again, that does not make sence. Note that you should focus on fpc. Lazarus has nothing to do with this. TryAdd simply works, as demonstrated above. If the example from Bytebites fails you have an old version and not a release version of 3.2.2.. BTW @Sarah: You have a sneaky way to implement features....Respect. ---------------------------------------------------------------------- PascalDragon · 2022-01-12 08:36 Quote from: Vaytl on January 11, 2022, 05:20:03 pmQuote from: PascalDragon on January 11, 2022, 10:14:22 am@Vaytl: what version of FPC/Lazarus are you using? Lazarus IDE v2.2.0RC1 r65419 X64 FPC: 3.2.2 Please try the example provided by bytebites. If that works the error is somewhere else in the code you want to convert (can you maybe post the full source, or is it available somewhere public?). If not then you'd need to check whether you're really using FPC 3.2.2. Quote from: Vaytl on January 11, 2022, 05:20:03 pmBTW @Sarah: You have a sneaky way to implement features....Respect. Sneaky enough that I didn't remember it myself. Then again I only applied a patch... ---------------------------------------------------------------------- Vaytl · 2022-01-12 10:23 I copied the files: inc\ generics.collections.pas generics.defaults.pas generics.hashes.pas generics.helpers.pas generics.memoryexpanders.pas generics.strings.pas to the project folder, after which the error disappeared. Thanks everyone. ---------------------------------------------------------------------- Thaddy · 2022-01-12 10:50 That is not a real solution. That means an older version of generics.collections is in your path. You need to solve that first.