中国开发网: 论坛: 程序员情感CBD: 贴子 564511
haitao
看procedure TCustomComboBox.KeyPress(var Key: Char);,是有延时判断和取按键消息。。。。。。
看procedure TCustomComboBox.KeyPress(var Key: Char);,是有延时判断和取按键消息。。。。。。

而现象也是:下拉选项只有0,1,2,...,99,100
快速依次按1234这4个键时,值先是12,最后很快变为34,如果立即按回车
下拉框是移到下一行了,但是内容是12(先输入的),而不是上一行的34!
连按n个数字,到下一行主动上去的前2个字符,而上一行的内容是第n-1,n个字符!

如果不用回车,改为在别的cell上点击鼠标,则很正常
如果回车慢点按,也很正常
现在在下拉框的按键事件里延时500毫秒,也很正常

把引发结束到下一行的按揭由回车改为'0',情况也是一样!

感觉是TCustomComboBox.KeyPress里,但是不知道怎么跟踪:快速按键,一跟踪就不快了

inherited KeyPress(Key);
if not AutoComplete then exit;
if Style in [csDropDown, csSimple] then
FFilter := Text
else
begin
if GetTickCount - FLastTime >= 500 then
FFilter := '';
FLastTime := GetTickCount;
end;
case Ord(Key) of
VK_ESCAPE: exit;
VK_TAB:
if FAutoDropDown and DroppedDown then
DroppedDown := False;
VK_BACK:
begin
if HasSelectedText(StartPos, EndPos) then
DeleteSelectedText
else
if (Style in [csDropDown, csSimple]) and (Length(Text) > 0) then
begin
SaveText := Text;
LastByte := StartPos;
while ByteType(SaveText, LastByte) = mbTrailByte do Dec(LastByte);
OldText := Copy(SaveText, 1, LastByte - 1);
SendMessage(Handle, CB_SETCURSEL, -1, 0);
Text := OldText + Copy(SaveText, EndPos + 1, MaxInt);
SendMessage(Handle, CB_SETEDITSEL, 0, MakeLParam(LastByte - 1, LastByte - 1));
FFilter := Text;
end
else
begin
while ByteType(FFilter, Length(FFilter)) = mbTrailByte do
Delete(FFilter, Length(FFilter), 1);
Delete(FFilter, Length(FFilter), 1);
end;
Key := #0;
Change;
end;
else // case
if FAutoDropDown and not DroppedDown then
DroppedDown := True;
if HasSelectedText(StartPos, EndPos) then
SaveText := Copy(FFilter, 1, StartPos) + Key
else
SaveText := FFilter + Key;

if Key in LeadBytes then
begin
if PeekMessage(Msg, Handle, 0, 0, PM_NOREMOVE) and (Msg.Message = WM_CHAR) then
begin
if SelectItem(SaveText + Char(Msg.wParam)) then
begin
PeekMessage(Msg, Handle, 0, 0, PM_REMOVE);
Key := #0
end;
end;
end
else
if SelectItem(SaveText) then
Key := #0
end; // case
我的blog:http://szhaitao.blog.hexun.com & http://www.hoolee.com/user/haitao
--以上均为泛泛之谈--
不尽牛人滚滚来,无边硬伤纷纷现 人在江湖(出来的),哪能不挨刀(总归是要的)
网络对话,歧义纷生;你以为明白了对方的话,其实呢?

您所在的IP暂时不能使用低版本的QQ,请到:http://im.qq.com/下载安装最新版的QQ,感谢您对QQ的支持和使用

相关信息:


欢迎光临本社区,您还没有登录,不能发贴子。请在 这里登录