Unit unit1;interfaceuses Windows, Messages, sysutils, variants, Classes, Graphics, Controls, Forms, Dialogs, Stdctrls;ty PE TForm1 = Class (Tform) Button1:tbutton; Button2:tbutton; Procedure Button1Click (Sender:tobject); Procedure Formcreate (Sender:tobject); Procedure Formdestroy (Sender:tobject); Procedure Button2click (Sender:tobject); Private {Private declarations} public {public declarations} End;var form1:tform1;implementation{$R *.dfm}use s inifiles; Thashedstringlist from Inifiles unit var hash:thashedstringlist; {thashedstringlist inherits from Tstringlist, only covers IndexOf, indexofname two methods to increase efficiency; If you focus on efficiency and do not need too much functionality, you can use Tstringhash, which is directly from the TObject inherited array list}//build hash table procedure Tform1.formcreate (sender:tobject); var i:inte Ger;begin Hash: = thashedstringlist.create; For I: = $ to 122 does begin Hash.add (CHR (i) + ' = ' + inttostr (i)); End ShowMessage (Hash.text); {构建结果: 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;//检索哈希表procedure TForm1.But Ton1click (Sender:tobject); var i:integer;begin i: = Hash.indexof (' z=122 '); ShowMessage (IntToStr (i)); I: = Hash.indexofname (' z '); ShowMessage (IntToStr (i)); 25end;//Basic Operation procedure Tform1.button2click (sender:tobject); Begin hash.values[' a ']: = ' 65 '; Assignment Hash.valuefromindex[0]: = ' 65 '; Assign a value showmessage (hash.values[' z ') with an index; 122, take value showmessage (hash.valuefromindex[25]),//122, use index value {Other operations to participate in Tstringlist}end;procedure Tform1.formdestroy ( Sender:tobject); Begin Hash.free;end;end.
[Go to]:delphi in hash table (1): Thashedstringlist