delphi – Sorting TDictionary by a key of Integer in ascending order – Stack Overflow
Posted by jpluimers on 2019/05/30
Great answer on [WayBack] delphi – Sorting TDictionary by a key of Integer in ascending order – Stack Overflow by J… comes down to this:
var LDictionary : TDictionary<Integer, string>; LArray : TArray<Integer>; ... LArray := LDictionary.Keys.ToArray(); TArray.Sort<Integer>(LArray);
I was trying the wrong direction (functional approach like LArray := LDictionary.Keys.ToArray.Sort();
), but the above procedural solution works.
Members used:
- [WayBack] Generics.Collections.TDictionary.Keys (introduced in Delphi 2009)
- [Archive.is] Generics.Collections.TDictionary.TKeyCollection.ToArray – XE API Documentation
- [WayBack] Generics.Collections.TArray.Sort Method (introduced in Delphi 2009)
–jeroen
Stefan Glienke said
Or you just use Spring4D and write LDictionary.Keys.Ordered