balabuev 102 Posted June 24 Did you know that the following will automatically work with TDictionary: type TMyKey = record public class operator Equal(const A, B: TMyKey): Boolean; function GetHashCode: Integer; end; Without the need to write custom equality comparer. At least in Delphi 12 it works. And System.TypeIfo unit contains GetRecCompareAddrs function, which is used in default equality comparer implementation. I realized it only recently, and see no docs/info on the internet. 5 Share this post Link to post
pyscripter 689 Posted June 24 (edited) Just keep in mind [RSP-43423] Using {$WEAKLINKRTTI ON} causes access violation on TList<T>.IndexOf method - Embarcadero Technologies, See also Edited June 24 by pyscripter 1 Share this post Link to post
A.M. Hoornweg 144 Posted June 25 15 hours ago, balabuev said: Did you know that the following will automatically work with TDictionary: type TMyKey = record public class operator Equal(const A, B: TMyKey): Boolean; function GetHashCode: Integer; end; Without the need to write custom equality comparer. At least in Delphi 12 it works. And System.TypeIfo unit contains GetRecCompareAddrs function, which is used in default equality comparer implementation. I realized it only recently, and see no docs/info on the internet. Hey, that's actually really cool! Share this post Link to post
Sisko 0 Posted September 10 It's cool BUT it's also very slow. see https://embt.atlassian.net/servicedesk/customer/portal/1/RSS-886 A generic list takes 100x longer to be generated than before (Delphi 11.3) Share this post Link to post
Der schöne Günther 316 Posted September 10 It it sufficient to have an equality operator or is the GetHashCode(): Integer method needed as well? Share this post Link to post
Stefan Glienke 2002 Posted September 11 Of course - TDictionary<K,V> is hashtable based, so it needs GetHashCode and Equals Share this post Link to post
pyscripter 689 Posted September 12 On 6/24/2024 at 6:28 PM, balabuev said: Did you know that the following will automatically work with TDictionary: This will no longer work by default in Delphi 12.2. You would need to add to your code: System.TypInfo.GetRecCompareAddrs := System.TypInfo.GetRecordCompareAddrs; Also using {$WEAKLINKRTTI ON} no longer causes crashes. It just results in using the default equality and GetHashCode functions. Share this post Link to post