Im learning Delphi but loved to use hash arrays in Perl and Java. Are there compairing data structures in Delphi?
I know that It is possible to use TStringList as a Hash Array :
var myHash:TStringList); begin myHash:=TStringList.Create(); myHash.values['color']:='blue'; Showmessage(myHash.Values['color']); //blue myHash.free; end;
Is it possible to build more complicated data structures like Perl’s hash of arrays etc. in Delphi?
Answer
If you’re using Delphi 2009 or later (and hopefully later, because there was a serious bug in the original implementation) you can find the TDictionary
class in the Generics.Collections
unit. TDictionar<TKey, TValue>
functions as a hash-map of keys to values, which should be exactly what you’re looking for.