?? 在delphi中用拼音首字符序列來實現檢索功能.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]<>'?') and
(UpperCase(PYIndexStr[j]) <>
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 + -