Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there Hash Arrays in Delphi?

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?

like image 407
user3133542 Avatar asked Aug 19 '14 18:08

user3133542


1 Answers

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.

like image 186
Mason Wheeler Avatar answered Nov 08 '22 13:11

Mason Wheeler