[Go to]:delphi in hash table (1): Thashedstringlist

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.