⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 在delphi中用拼音首字符序列来实现检索功能.htm

📁 对于学习很有帮助
💻 HTM
字号:
<html><!-- #BeginTemplate "/Templates/最新一般文章.dwt" -->
<head>
<!-- #BeginEditable "doctitle" --> 
<title>在Delphi中用拼音首字符序列来实现检索功能 </title>
<!-- #EndEditable --> 
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="编程技术大全" content="编程技术大全,C、C++、Delphi、Java">
<meta name="keywords" content="编程 C C++ Basic Pascal Java Html 数据库 软件 使用 大全 资料">
</head>
<style type="text/css">
<!--
.unnamed1 {  color: #000000; text-decoration: none; font-size: 9pt}
-->
</style></head>

<body bgcolor="#C9DDE0">
<table width="100%" border="0">
  <tr> 
    <td width="49%">
      <table width="103%" border="0">
        <tr> 
          <td width="51%"><a href="../../index.html" class="unnamed1">首页</a></td>
          <td width="49%" bgcolor="#FF3333"> 
            <div align="center"><font color="#FFFF33"><b>★</b></font><b><a href="http://home4u.china.com/technology/programming/verybook/" target="_blank"><font color="#FFFFCC">编程书籍下载</font></a></b><font color="#FFFF33"><b>★</b></font></div>
          </td>
        </tr>
      </table>
    </td>
    <td width="41%" class="unnamed1">
      <div align="right">New Win98帮助格式 本站所有文章都提供打包下载</div>
    </td>
    <td width="10%"><a href="../../download.html">下载资料</a></td>
  </tr>
</table>
<div align="center">由于碧海银沙有时不支持断线续载,如果您有不能下载的东西,请到<a href="http://go.163.com/%7Everybeauty">网易站</a><br>
  对于Turbo C、Turbo C++、Turbo Pascal这些编译器,请到<a href="http://home4u.china.com/technology/programming/verybook/" target="_blank">快意恩仇书社的编程资料</a>相关栏目下载 
  <br>
</div>
<hr size="4">
<table width="75%" border="0" align="center">
  <tr> 
    <td> 
      <div align="center">
        <script src="http://best.163.com/~blueflybird/ad/banneru_bird.js"></script>
      </div>
    </td>
  </tr>
</table>
<div align="center"></div>
<p><br>
</p>
<table width="80%" border="0" align="center">
  <tr> 
    <td><!-- #BeginEditable "%B7%D6%C0%E0" -->
      <center>
        <b><font style="FONT-SIZE: 16.5pt" color="#FF6666" face="楷体_GB2312">在Delphi中用拼音首字符序列来实现检索功能</font></b>
      </center>
      <hr color="#EE9B73" size="1" width="94%">
      <p><span style="font-size: 9pt"><font color="#ffffff">----</font> 在日常工作和生活中我们经常使用电子记事本查找个人通讯录信息,或在单位的应用程序中查询客户档案或业务资料,这个过程中往往需要输入大量的汉字信息,对于熟悉计算机的人这已经是一件头疼的事,那些不太熟悉计算机或根本不懂汉字输入的用户简直就望而生畏。作为对数据检索技术的一种新的尝试,作者探索使用汉字拼音的首字符序列作为检索关键字,这样,用户不必使用汉字,只须简单地键入要查询信息的每个汉字的拼音首字符即可。比如你想查找关键字“中国人民银行”,你只需要输入“zgrmyh”。作者希望通过下面的例子,为广大计算机同行起一个抛砖引玉的作用,让我们开发的程序更加便捷、好用。 
        </span> 
      <p><span style="font-size: 9pt"><font color="#ffffff">----</font> 原理很简单,找出汉字表中拼音首字符分别为“A”至“Z”的汉字内码范围,这样,对于要检索的汉字只需要检查它的内码位于哪一个首字符的范围内,就可以判断出它的拼音首字符。 
        </span> 
      <p><span style="font-size: 9pt"><font color="#ffffff">----</font> 程序更简单,包括3个控件:一个列表存放着所有待检索的信息;一个列表用于存放检索后的信息;一个编辑框用于输入检索关键字(即拼音首字符序列)。详细如下: 
        </span> 
      <p><span style="font-size: 9pt"><font color="#ffffff">----</font> 1.进入Delphi创建一个新工程:Project1 
        </span> 
      <p><span style="font-size: 9pt"><font color="#ffffff">----</font> 2.在Form1上创建以下控件并填写属性: 
        </span></p>
      <br>
      <pre><span style="font-size: 9pt">控件类型      属性名称  属性值
Edit           Name      Search
ListBox        Name      SourceList
Items      输入一些字符串,如姓名等,用于提供检索数据
ListBox        Name      ResultList</span></pre>
      <br>
      <p><font color="#ffffff"><span style="font-size: 9pt"> </span> </font>
      <p><font color="#ffffff"><span style="font-size: 9pt">----</span></font><span style="font-size: 9pt"> 
        3.键入以下两个函数 </span></p>
      <br>
      <pre><span style="font-size: 9pt">// 获取指定汉字的拼音索引字母,如:“汉”的索引字母是“H”
function GetPYIndexChar( hzchar:string):char;
begin
case WORD(hzchar[1]) shl 8 + WORD(hzchar[2]) of
$B0A1..$B0C4 : result := 'A';
$B0C5..$B2C0 : result := 'B';
$B2C1..$B4ED : result := 'C';
$B4EE..$B6E9 : result := 'D';
$B6EA..$B7A1 : result := 'E';
$B7A2..$B8C0 : result := 'F';
$B8C1..$B9FD : result := 'G';
$B9FE..$BBF6 : result := 'H';
$BBF7..$BFA5 : result := 'J';
$BFA6..$C0AB : result := 'K';
$C0AC..$C2E7 : result := 'L';
$C2E8..$C4C2 : result := 'M';
$C4C3..$C5B5 : result := 'N';
$C5B6..$C5BD : result := 'O';
$C5BE..$C6D9 : result := 'P';
$C6DA..$C8BA : result := 'Q';
$C8BB..$C8F5 : result := 'R';
$C8F6..$CBF9 : result := 'S';
$CBFA..$CDD9 : result := 'T';
$CDDA..$CEF3 : result := 'W';
$CEF4..$D188 : result := 'X';
$D1B9..$D4D0 : result := 'Y';
$D4D1..$D7F9 : result := 'Z';
else
result := char(0);
end;
end;
<br>
// 在指定的字符串列表SourceStrs中检索符合拼音索引字符串
PYIndexStr的所有字符串,并返回。
function SearchByPYIndexStr
( SourceStrs:TStrings;
PYIndexStr:string):string;
label NotFound;
var
i, j   :integer;
hzchar :string;
begin
for i:=0 to SourceStrs.Count-1 do
begin
for j:=1 to Length(PYIndexStr) do
begin
hzchar:=SourceStrs[i][2*j-1]
+ SourceStrs[i][2*j];
if (PYIndexStr[j]&lt;&gt;'?') and
(UpperCase(PYIndexStr[j]) &lt;&gt;
GetPYIndexChar(hzchar)) then goto NotFound;
end;
if result='' then result := SourceStrs[i]
else result := result + Char
(13) + SourceStrs[i];
NotFound:
end;
end;
<br>
4.增加编辑框Search的OnChange事件:
procedure TForm1.SearchChange(Sender: TObject);
var ResultStr:string;
begin
ResultStr:='';
ResultList.Items.Text := SearchByPYIndexStr
(Sourcelist.Items, Search.Text);
end; </span></pre>
      <br>
      <p><font color="#ffffff"><span style="font-size: 9pt"> </span> </font>
      <p><font color="#ffffff"><span style="font-size: 9pt">----</span></font><span style="font-size: 9pt"> 
        5.编译运行后,在编辑框Search中输入要查询字符串的拼音首字符序列,检索结果列表ResultList就会列出检索到的信息,检索中还支持“?”通配符,对于难以确定的的文字使用“?”替代位置,可以实现更复杂的检索。 
        </span> 
      <p><span style="font-size: 9pt"><font color="#ffffff">----</font> 本程序在Delphi4.0中编译运行通过。 
        </span></p>
      <!-- #EndEditable --></td>
  </tr>
</table>
<hr size="4">
<table width="75%" border="0" align="center">
  <tr> 
    <td> 
      <div align="center">
        <script src="http://best.163.com/~blueflybird/ad/bannerd_bird.js"></script>
      </div>
    </td>
  </tr>
</table>
<span class="unnamed1"><span class="unnamed1"> </span></span> 
<p align="center"><span class="unnamed1"><span class="unnamed1"><span class="unnamed1">飞鸟工作室 
  1999 有任何意见和建议</span></span>请发</span><a href="mailto:blueflybird@163.net">Email</a></p>
</body>
<!-- #EndTemplate --></html>
<html>
<head>
<title></title>
<script language="JavaScript">
function showhide() {
  var i, ss, cc, rr;
  cc = showhide.arguments;
  for (i=0; i<(cc.length-2); i+=3) 
     {  ss   = cc[i+2];
       if (navigator.appName == 'Netscape' && docu

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -