unit Unit1;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Grids, DBGrids, Db, ADODB, Psock, NMMSG;type
TForm1 = class(TForm)
ADOTable1: TADOTable;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
Edit1: TEdit;
procedure Edit1Change(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure DBGrid1KeyPress(Sender: TObject; var Key: Char);
private
{ Private declarations }
public
SearchStr:String;
lastTime:integer;
lastField:String;
lastrec:integer;
search:boolean;
{ Public declarations }
end;var
Form1: TForm1;
function SearchByPYIndexStr(SourceStrs:string;PYIndexStr:string):boolean;
function GetPYIndexChar( hzchar:string):char;
implementation{$R *.DFM}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;
function SearchByPYIndexStr(SourceStrs:String;PYIndexStr:string):boolean;
label NotFound;
var
i, j :integer;
hzchar :string;
begin
result:=false;
begin
for j:=1 to Length(PYIndexStr) do
begin
hzchar:=SourceStrs[2*j-1]+SourceStrs[2*j];
if (PYIndexStr[j]<>'?') and
(UpperCase(PYIndexStr[j]) <>GetPYIndexChar(hzchar)) then goto NotFound;
end;
result:=true;
end;
NotFound:
end;
procedure TForm1.Edit1Change(Sender: TObject);
var
i:integer;
endit:boolean;
begin
dbgrid1.datasource.dataset.first;
endit:=false;
while not endit do
begin
if SearchByPYIndexStr(dbgrid1.datasource.DataSet.Fields[0].AsString,edit1.text) then endit:=true;
if (not dbgrid1.DataSource.DataSet.eof) then
begin
if not endit then
dbgrid1.DataSource.DataSet.Next;
end
else begin
endit:=true;
dbgrid1.datasource.dataset.First;
end;
end;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
search:=true;
end;procedure TForm1.DBGrid1KeyPress(Sender: TObject; var Key: Char);
var
i:integer;
endit:boolean;
TheField:string;
begin
with TDBGrid(sender) do
begin
TheField:=SelectedField.FieldName;
if search then
begin
if lastfield=thefield then
if lasttime<(gettickcount-1100) then
SearchStr:='';
searchStr:=SearchStr+key;
lasttime:=gettickcount();
lastfield:=TheField;
//tadodataset(DataSource.DataSet).Locate(thefield,searchstr,[loCaseInsensitive,loPartialKey]);
datasource1.DataSet:=nil;
while not endit do
begin
if UpperCase(copy(dbgrid1.SelectedField.AsString,0,length(searchStr)))=UpperCase(SearchStr) then endit:=true;
if SearchByPYIndexStr(dbgrid1.SelectedField.AsString,searchStr) then endit:=true;
if (not dbgrid1.DataSource.DataSet.eof) then
begin
if not endit then
dbgrid1.DataSource.DataSet.Next;
end
else
begin
endit:=true;
dbgrid1.datasource.dataset.First;
end;
end;
datasource1.DataSet:=adotable1;
key:=#0;
end;
end;
end;end.
edit 1个,dbgrid 1个,自己看看吧,随便改点就行
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Grids, DBGrids, Db, ADODB, Psock, NMMSG;type
TForm1 = class(TForm)
ADOTable1: TADOTable;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
Edit1: TEdit;
procedure Edit1Change(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure DBGrid1KeyPress(Sender: TObject; var Key: Char);
private
{ Private declarations }
public
SearchStr:String;
lastTime:integer;
lastField:String;
lastrec:integer;
search:boolean;
{ Public declarations }
end;var
Form1: TForm1;
function SearchByPYIndexStr(SourceStrs:string;PYIndexStr:string):boolean;
function GetPYIndexChar( hzchar:string):char;
implementation{$R *.DFM}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;
function SearchByPYIndexStr(SourceStrs:String;PYIndexStr:string):boolean;
label NotFound;
var
i, j :integer;
hzchar :string;
begin
result:=false;
begin
for j:=1 to Length(PYIndexStr) do
begin
hzchar:=SourceStrs[2*j-1]+SourceStrs[2*j];
if (PYIndexStr[j]<>'?') and
(UpperCase(PYIndexStr[j]) <>GetPYIndexChar(hzchar)) then goto NotFound;
end;
result:=true;
end;
NotFound:
end;
procedure TForm1.Edit1Change(Sender: TObject);
var
i:integer;
endit:boolean;
begin
dbgrid1.datasource.dataset.first;
endit:=false;
while not endit do
begin
if SearchByPYIndexStr(dbgrid1.datasource.DataSet.Fields[0].AsString,edit1.text) then endit:=true;
if (not dbgrid1.DataSource.DataSet.eof) then
begin
if not endit then
dbgrid1.DataSource.DataSet.Next;
end
else begin
endit:=true;
dbgrid1.datasource.dataset.First;
end;
end;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
search:=true;
end;procedure TForm1.DBGrid1KeyPress(Sender: TObject; var Key: Char);
var
i:integer;
endit:boolean;
TheField:string;
begin
with TDBGrid(sender) do
begin
TheField:=SelectedField.FieldName;
if search then
begin
if lastfield=thefield then
if lasttime<(gettickcount-1100) then
SearchStr:='';
searchStr:=SearchStr+key;
lasttime:=gettickcount();
lastfield:=TheField;
//tadodataset(DataSource.DataSet).Locate(thefield,searchstr,[loCaseInsensitive,loPartialKey]);
datasource1.DataSet:=nil;
while not endit do
begin
if UpperCase(copy(dbgrid1.SelectedField.AsString,0,length(searchStr)))=UpperCase(SearchStr) then endit:=true;
if SearchByPYIndexStr(dbgrid1.SelectedField.AsString,searchStr) then endit:=true;
if (not dbgrid1.DataSource.DataSet.eof) then
begin
if not endit then
dbgrid1.DataSource.DataSet.Next;
end
else
begin
endit:=true;
dbgrid1.datasource.dataset.First;
end;
end;
datasource1.DataSet:=adotable1;
key:=#0;
end;
end;
end;end.
edit 1个,dbgrid 1个,自己看看吧,随便改点就行
★ 袁飞汉字拼音互查控件 1.2 版 2002-5-15 20:44:04 38 185.80 K(包含演示程序)
袁飞汉字拼音互查控件 1.2 版!
新增功能:
1、添加取汉字之“常用拼音”功能。
2、添加取汉字之“拼音首码”功能。
3、改进算法,大大压缩身躯!(1.0 版控件为2.78M, 1.2 版仅 428K)软件性质: 免费