Delphi 中实现汉字拼音声母查询, unité 代码如下 :
unité unité 1;
interface
usages
Windows, messages, systèmes, classes, graphiques, contrôles, formulaires, dialogues,
Stdctrls;
taper
Tform1 = classe (tform)
Listbox1: tlistbox;
Listbox2: tlistbox;
Edit1: Tedit;
Label1: Tlabel;
Procédure Edit1Change (expéditeur: tobject);
Procédure FormShow (expéditeur: tobject);
Procédure FormDestroy (expéditeur: tobject);
Procédure Edit1enter (expéditeur: tobject);
Procédure Edit1Exit (expéditeur: tobject);
privé
{Déclarations privées}
publique
ResultList1: TStrings;
fin;
var
FORM1: TFORM1;
Procédure SearchByPyIndexstr (pyindexstr: string);
mise en œuvre
{$ R * .dfm}
fonction getpyIndexChar (hzchar: string): String;
commencer
cas (word (hzchar [1]) shl 8 + mot (hzchar [2])) de
$ B0a1 .. $ b0c4: résultat: = 'a';
$ B0c5 .. $ b2c0: résultat: = 'b';
$ B2c1 .. $ b4ed: résultat: = 'c';
$ B4ee .. $ b6e9: résultat: = 'd';
$ B6ea .. $ b7a1: résultat: = 'e';
$ B7a2 .. $ b8c0: résultat: = 'f';
$ B8c1 .. $ b9fd: résultat: = 'g';
$ B9fe .. $ bbf6: résultat: = 'h';
$ Bbf7 .. $ bfa5: résultat: = 'j';
$ Bfa6 .. $ c0ab: résultat: = 'k';
$ C0AC .. $ C2E7: Résultat: = 'l';
$ C2E8 .. $ C4C2: Résultat: = 'M';
$ C4C3 .. $ C5B5: Résultat: = 'n';
$ C5B6 .. $ C5BD: Résultat: = 'O';
$ C5BE .. $ C6D9: Résultat: = 'P';
$ C6da .. $ c8ba: résultat: = 'q';
$ C8BB .. $ C8F5: Résultat: = 'r';
$ C8f6 .. $ cbf9: résultat: = 's';
$ Cbfa .. $ cdd9: résultat: = 't';
$ Cdda .. $ cef3: résultat: = 'w';
$ Cef4 .. $ d1b8: résultat: = 'x';
$ D1b9 .. $ d4d0: résultat: = 'y';
$ D4d1 .. $ d7f9: résultat: = 'z';
autre
Résultat: = char (0);
fin;
fin;
Procédure SearchByPyIndexstr (pyindexstr: string);
Étiquette Notfound;
var
I, J: entier;
HZCHAR: String;
commencer
Pour i: = 0 à for1.listbox1.items.count-1 do
commencer
Pour j: = 1 à la longueur (pyindexstr) faire
commencer
Hzchar: = form1.listbox1.items [i] [2 * j-1] + form1.listbox1.items [i] [2 * j];
if (pyindexstr [j] <> '?') et (uppercase (pyindexstr [j]) <> getpyindexchar (hzchar)) puis
Goto Notfound;
fin;
Form1.resultList1.add (form1.listbox1.items [i]);
Pas-fond:
fin;
fin;
Procédure TForm1.Edit1Change (expéditeur: tobject);
commencer
Si Edit1.Text <> '' alors
commencer
Listbox2.items.clear;
Form1.resultList1.Clear;
SearchByPyIndexstr (edit1.text);
Listbox2.items.addStrings (resultList1);
fin;
fin;
Procédure tform1.formShow (expéditeur: tobject);
commencer
ResultList1: = tStringList.create;
fin;
Procédure tform1.formDestroy (expéditeur: tobject);
commencer
ResultList1.free;
fin;
Procédure tform1.edit1enter (expéditeur: tobject);
commencer
Edit1.text: = '';
fin;
Procédure tform1.edit1Exit (expéditeur: tobject);
commencer
Edit1.text: = '请输入声母';
fin;
fin.