Categories
discuss

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:…

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.

Source: stackoverflow
Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Privacy Policy, and Copyright Policy. Content is available under CC BY-SA 3.0 unless otherwise noted. The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 © No Copyrights, All Questions are retrived from public domain..