请问在下拉菜单的控件中如何实现自动检索的功能? (50分)

  • 主题发起人 主题发起人 asiancat
  • 开始时间 开始时间
A

asiancat

Unregistered / Unconfirmed
GUEST, unregistred user!
比如说:下拉菜单有aaa,abc ,adg,bdd,bik,clo,cke
用户输入一个b则以b开头的自动向上跳,再输入一个i则bik跳到第一个
 
有一个find函数
 
给我多少分呀,这个我做过
 
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 := 'Y';
$D4D1..$D7F9 : result := 'Z';
else
result := char(0);
end;
end;

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[2*j-1]+ SourceStrs[2*j];
if (PYIndexStr[j]<>'?')and(UpperCase(PYIndexStr[j])<>GetPYIndexChar(hzchar)) then
goto NotFound;
end;
if result='' then
result := SourceStrs
else result := result + Char(13) + SourceStrs;
NotFound:
end;
end;

procedure TForm1.SearchChange(Sender: TObject);
var ResultStr:string;
begin
ResultStr:='';
ResultList.Items.Text := SearchByPYIndexStr(Sourcelist.Items, Search.Text);

end;

end.
 
如果是combobox之类,请设置AutoComplete为True,看看combobox的源码,稍做修改就可以了,而且支持汉字索引。
 
sail_world我会按照你的方法去试的,如果可以用,我给再给你加100分,如何?
请给我你的e_mail,thanks!
 
谢谢你了哥们,我也是学这个的,有什么困难我们一起学
把分给我吧,我的分也很少
lijw@mail.csoft.com.cn
 
好使吗,一定好使,这个是我做的,这样吧,把你的信箱给我说我把例子发到你的邮箱里
 
to sail_world
asiancat@sina.com
thanks!
 
你还没有给我分呀
快给我分吧,我把做的都给你,
 
我再开个帖子,给你一百分。这个帖子的分值已经没有办法改变了
谢谢
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
后退
顶部