eate(Sender: TObject);
procedure Edit1Change(Sender: TObject);
procedure ListBox2Click(Sender: TObject);
procedure ListBox1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
SelectPY: TSelectPY;
getName:String;
{函数在这里定义}
function GetCharInd(zzchar:string):char;//汉字拼音码
function DisByStrInd(ListBoxStr:TListBox;StrInd:string):string;
implementation
uses DataMain;
{$R *.dfm}
{//汉字拼音码检索 对应的拼音字母}
function GetCharInd(zzchar:string):char;
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;
{汉字拼音码的检索}
function DisByStrInd(ListBoxStr:TListBox;StrInd:string):string;
label NotFound;
var
zzchar :string;
i,j:integer;
begin
for i:=0 to ListBoxStr.Items.Count-1 do
begin
for j:=1 to Length(StrInd) do
begin
zzchar:=ListBoxStr.Items[i][2*j-1]+ListBoxStr.Items[i][2*j];
if (StrInd[j]<>'?') and (UpperCase(StrInd[j])<>GetCharInd(zzchar))
then goto NotFound;
end;
if result='' then result:=ListBoxStr.Items[i]
else result:=result+#13+ListBoxStr.Items[i];
NotFound:
end;
end;
{在 FormCreate 中,将联系人 姓名 加入 ListBox1}
procedure TSelectPY.FormCreate(Sender: TObject);
var
i:integer;
begin
inherited;
with adodm.PersonName do
begin
listBox1.Clear;
//用循环的方法加入
for i:=0 to adodm.PersonName.RecordCount-1 do
begin
self.ListBox1.Items.Add(adodm.PersonName.FieldByName('姓名').AsString);
adodm.PersonName.Next;
end;
listBox1.Sorted:=true;
adodm.PersonName.First;//DateSet指针指向第一条记录
end;
// edit1.SetFocus;
end;
//实现单击选择性名
procedure TSelectPY.ListBox2Click(Sender: TObject);
var xIndex:integer;
begin
inherited;
xIndex:=self.ListBox2.ItemIndex;//得到Item选项的Index
label3.Caption:=self.ListBox2.Items.Strings[xIndex];//从Index得到 Text;
getName:=self.ListBox2.Items.Strings[xIndex];
end;
{输入拼音查找汉字}
procedure TSelectPY.Edit1Change(Sender: TObject);
var
SelStr:string;
begin
inherited;
SelStr:='';
ListBox2.Items.Text:=DisByStrInd(listBox1,Edit1.Text);
end;
{单击选择}
procedure TSelectPY.ListBox1Click(Sender: TObject);
var nIndex:integer;
begin
inherited;
nIndex:=ListBox1.ItemIndex;
ListBox2.Items.Text:=ListBox1.Items.Strings[nIndex];
getName:=self.ListBox2.Items.Text;
end;
end.
第1页:Delphi实现数据库的拼音查询(1) 第2页:Delphi实现数据库的拼音查询(2)
© CopyRight 2008-2010, JSJGZ.CN, 计算机故障 Inc. All Rights Reserved
闽ICP备09000710号 增值电信业务经营许可证闽B2-20080004号 Rss订阅