首先你应该在客户信息表当中建一个字段用来储存拼音,然后就按照这个字段来查询,最好这个拼音字段是取中文的第一个字母,在onchange中和onexit事件中写代码。我要这方面的代码,用的是第三方控件,不过还是要自己写一些简单的类,不过你的分数太少了!
解决方案 »
- 求物业管理系统自定义收费公式的设计思路
- 如何将edit框里输入的实数(如1112.52)插入到oracle 数据库类型为number的字段中?
- 有一句相当长的SQL要执行,程序在ADOQuery1.ExecSQL时就未响应了,怎么可以令程序运行到这时不会没响应?
- 连接access出了点问题
- stringGrid中怎样获取当前选中单元的行索引和列索引????(在线等待)
- 哪儿有dbexpress补丁下载?
- ■■高分求够delphi相关电子书籍下载网站■■
- 如何减少软件占用的系统资源???
- 寻求帮忙,全部奉送
- Delphi/Pascal 书目大全!
- ADODataSet的Filter怎么不起作用?
- delphi中如何进行乘方计算
const ChinaCode: array[0..25, 0..1] of Integer = ((1601, 1636), (1637, 1832), (1833, 2077),
(2078, 2273), (2274, 2301), (2302, 2432), (2433, 2593), (2594, 2786), (9999, 0000),
(2787, 3105), (3106, 3211), (3212, 3471), (3472, 3634), (3635, 3722), (3723, 3729),
(3730, 3857), (3858, 4026), (4027, 4085), (4086, 4389), (4390, 4557), (9999, 0000),
(9999, 0000), (4558, 4683), (4684, 4924), (4925, 5248), (5249, 5589));{ 在字符串前加入指定字符至字符串达到指定长度 }function HzPy(sr: string): string; //假如输入的一半是英文一半是中文
//的时候该修改这个函var
C1, Len1, C2: Integer;
ir: Word;
FResult: string;
begin
FResult := '';
C1 := 1;
Len1 := Length(sr);
while (C1 <= Len1) do
begin
if (ord(sr[C1]) >= 160) and (ord(sr[C1 + 1]) >= 160) then
begin
ir := (ord(sr[C1]) - 160) * 100 + ord(sr[C1 + 1]) - 160;
C2 := 1;
while (C2 <= 26) do
begin
if (ir >= ChinaCode[C2, 0]) and (ir <= ChinaCode[C2, 1]) then
begin
FResult := FResult + chr(C2 + ord('a'));
break;
end;
C2 := C2 + 1;
end;
end;
C1 := C1 + 2;
end;
Result := FResult;
end;
上面这个函数还有一点小毛病,我代码中已经写出来了,还望高手指点一二!
begin
case WORD(zzchar[1]) shl 8+WORD(zzchar[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:=#0;
end;
end;
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
edtHz: TEdit;
edtPy: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.DFM}
//
//例程名:GetPy
// 参数:输入参数:Hz,为一任一汉字或一字符
// 输出 :一拼音字母
// 功能:本列程完成汉字转换其对应拼音首字母的功能,输入若为一汉字,
// 则输出对应汉字拼音的第一个字母,若为其它,则不转换输出
//function Hz2Py(hz:string):char;
begin
case WORD(hz[1]) shl 8 + WORD(hz[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(32);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i: Integer;
sPy: string;
sTemp: string;
begin
sTemp := '' ;
i := 1;
while i <= Length(edtHz.Text) do
begin
sPy := Copy(edtHz.Text, i , 1);
if sPy >= Chr(128) then
begin
Inc(i);
sPy := sPy + Copy(edtHz.Text, i , 1);
sTemp := sTemp + Hz2Py(sPy);
end
else
sTemp := sTemp + sPy;
Inc(i);
end;
edtPy.Text := sTemp;
end;end.
你先看看,http://CoolSlob.8u8.com -> 下载专区 -> 版主拙作
不过,因上网条件所限,现不能上传源程序.
wolfAone(黑色的狼(WOLF)):你的代码我已经试过了,可以解决我的问题,不过好像有些汉字转换不出来,比如“魅”就不行的,我没测试很多。
horlen(少爷的破拐杖) :你的代码我也试了,但不转换数字与英文。分数肯定是要给的。
对了,可以不可以实现转换成姓名完整汉语拼音?希望大家多多讨论。
[email protected]
或者
[email protected]谢谢.
[email protected]
发过来我测试一下.
也可以去delphibbs.com 看看也很多。我的这个问题就是在这里解决的。
//汉字内码集********************************************************************
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
const CHNCode: array[0..25, 0..1] of Integer = ((1601, 1636), (1637, 1832), (1833, 2077),
(2078, 2273), (2274, 2301), (2302, 2432),
(2433, 2593), (2594, 2786), (9999, 0000),
(2787, 3105), (3106, 3211), (3212, 3471),
(3472, 3634), (3635, 3722), (3723, 3729),
(3730, 3857), (3858, 4026), (4027, 4085),
(4086, 4389), (4390, 4557), (9999, 0000),
(9999, 0000), (4558, 4683), (4684, 4924),
(4925, 5248), (5249, 5589));//==============================================================================
///取得汉字的拼音的首字母*******************************************************
//==============================================================================
function GetCHNPinYin(const CHNStr: string): string;
var i, j, CHNOrd: integer;
begin
i := 1;
while i<=Length(CHNStr) do
begin
if (CHNStr[i]>=#160) and (CHNStr[i+1]>=#160)
then begin
CHNOrd := (Ord(CHNStr[i]) - 160) * 100 + Ord(CHNStr[i+1]) - 160;
for j := 0 to 25 do
begin
if (CHNOrd >= CHNCode[j][0]) and (CHNOrd <= CHNCode[j][1])
then begin
Result := Result + Char(Byte('A') + j);
Break;
end;
end;
Inc(i);
end else Result := Result + CHNStr[i];
Inc(i);
end;
end;
// FileName: PY.pas
//
// Copyright (C) 1999 By Zhang Qing
//
// You can use and modify it ,but please send me an email.
//
// E-Mail: [email protected]
/////////////////////////////////////////////////////////////////////////////
unit PY;interface
uses sysutils;// 获取汉字的拼音首字符,这个函数将用在GetPYIndexStr 中.
function GetPYIndexChar(strChinese: string; bUpCase: Boolean = True): char;// 获取多个汉字的拼音首字符组成的字符串.
function GetPYIndexStr(strChinese: string; bUpCase: Boolean = True): string;implementation////////////////////////////////////////////////////////////////////////////
// 函数: GetPYIndexChar(strChinese: string;bUpCase: Boolean = True): char;
//
// 函数功能:获取汉字的拼音首字符.
// 例: GetPYIndexChar('程') 将返回'C'.
//
// 注意:对于多于一个汉字的输入(string类型)只有第一个有效,但不会产生错误
// 例如,GetPYIndexChar('程序')也将返回'C'.
//
// 第二个参数决定返回大写还是小写 , 缺省为大写 .
////////////////////////////////////////////////////////////////////////////
function GetPYIndexChar(strChinese: string;bUpCase: Boolean = True): char;
begin
// 根据汉字表中拼音首字符分别为“A”至“Z”的汉字内码范围,
// 要检索的汉字只需要检查它的内码位于哪一个首字符的范围内,
// 就可以判断出它的拼音首字符。
case WORD(strChinese[1]) shl 8 + WORD(strChinese[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;
if not bUpCase then
begin // 转换为小写
result := Chr(Ord(result)+32);
end;
end;////////////////////////////////////////////////////////////////////////////
// 函数: GetPYIndexStr(strChinese: string;bUpCase: Boolean = True): string;
//
// 函数功能:获取多个汉字的拼音首字符组成的字符串.
// 例: GetPYIndexStr('程') 将返回'C'.
// GetPYIndexStr('程序')将返回'CX'.
//
// 第二个参数决定返回大写还是小写 , 缺省为大写 .
////////////////////////////////////////////////////////////////////////////
function GetPYIndexStr(strChinese: string;bUpCase: Boolean = True): string;
var
strChineseTemp : string;
cTemp : Char;
begin
result := '';
strChineseTemp := strChinese;
while strChineseTemp<>'' do
begin
cTemp := GetPYIndexChar(strChineseTemp);
if not bUpCase then
begin // 转换为小写
cTemp := Chr(Ord(cTemp)+32);
end;
result := result + string(cTemp);
strChineseTemp := Copy(strChineseTemp,3,Length(strChineseTemp));
end;
end;end.