Lazarus中文社区

 找回密码
 立即注册(注册审核可向QQ群索取)

QQ登录

只需一步,快速开始

Lazarus IDE and 组件 下载地址版权申明
查看: 2449|回复: 2

用arrow keys控制EDIT不起作用的问题

[复制链接]

该用户从未签到

发表于 2012-12-20 12:07:52 | 显示全部楼层 |阅读模式
上下方向键在EDIT不起作用的问题。很平常的代码:
uses windows;      
procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState
begin
if ((key=VK_DOWN) or (key=vk_return )) and  (activecontrol is Tedit) then
   begin
     Perform(WM_NEXTDLGCTL,0,0)
   end ;
end;
不起作用?到http://www.lazarus.freepascal.org/index.php/topic,14518.msg76888.html#msg76888找找   
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState );
begin
   caption:=chr(key);
end;

Will show that up arrow says '&'. This would basically mean you can't distinct arrow keys from typed characters with onKeyPress event.
And, how could it represent arrow keys as characters of 0..255? They go from 37..40.

回复

使用道具 举报

该用户从未签到

 楼主| 发表于 2012-12-20 13:07:28 | 显示全部楼层
no all code that works in delphi have to work or will work in fpc/lazarus, remember that delphi runs only under windows.
回复 支持 反对

使用道具 举报

该用户从未签到

 楼主| 发表于 2012-12-20 13:40:38 | 显示全部楼层
从上面的解释看,并不是全部代码都可以从DE移值到LA上,因为DE仅运行在windows下。
根据键值37 left,  38 up, 39 right, 40 down,改变代码如下:
procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState  );
begin
if ((Key=40) or (key=13))and(activecontrol is Tedit) then
begin
   SelectNext(ActiveControl,true, true);
end
else
if (key=38) and  (activecontrol is Tedit) then
begin
   SelectNext(ActiveControl,false,true);
end;
end;
可以实现按ENTER或向下方向键移动EDIT焦点了。

点评

恭喜你  发表于 2012-12-20 13:55
回复 支持 反对

使用道具 举报

*滑块验证:

本版积分规则

QQ|手机版|小黑屋|Lazarus中国|Lazarus中文社区 ( 鄂ICP备16006501号-1 )

GMT+8, 2026-5-16 19:23 , Processed in 0.037387 second(s), 12 queries , Redis On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表