turn from a blogthe hash table in Delphi: Thashedstringlist
UnitUnit1;InterfaceusesWindows, Messages, sysutils, variants, Classes, Graphics, Controls, Forms, Dialogs, Stdctrls;typeTForm1 =class(Tform) Button1:tbutton; Button2:tbutton;procedureButton1Click (Sender:tobject);procedureFormcreate (Sender:tobject);procedureFormdestroy (Sender:tobject);procedureButton2click (Sender:tobject);Private{Private declarations} Public{public declarations}End;varForm1:tform1;Implementation{$R *.DFM}usesInifiles;//thashedstringlist from Inifiles unitvarHash:thashedstringlist;{thashedstringlist inherits from Tstringlist, only covers IndexOf, indexofname two methods to increase efficiency; If you focus on efficiency and don't need too much functionality, you can use Tstringhash, which is an array-linked list that inherits directly from TObject}//Build hash table (can also be loaded from text file)procedureTform1.formcreate (Sender:tobject);varI:integer;beginHash: = thashedstringlist.create; forI: = the to 122 DobeginHash.add (CHR (i) +' = '+ INTTOSTR (i));End; ShowMessage (Hash.text);{build Result: a=97 b=98 c=99 d=100 e=101 f=102 g=103 h=104 i=105 j=106 k=107 l=108 m=109 n=110 o=111 p=112 q =113 r=114 s=115 t=116 u=117 v=118 w=119 x=120 y=121 z=122}End;//Retrieving a hash tableprocedureTform1.button1click (Sender:tobject);varI:integer;beginI: = Hash.indexof (' z=122 '); ShowMessage (IntToStr (i));//25I: = Hash.indexofname (' Z '); ShowMessage (IntToStr (i));//25End;//Basic OperationprocedureTform1.button2click (Sender:tobject);beginhash.values[' A '] :=' A ';//Assigned valuehash.valuefromindex[0] :=' A ';//Assign a value with an indexShowMessage (hash.values[' Z ']);//122, value by nameShowMessage (hash.valuefromindex[ -]);//122, using the index to take a value{Other actions participate in Tstringlist}End;procedureTform1.formdestroy (Sender:tobject);beginHash.free;End;End.
The hash table in Delphi: thashedstringlist