DELPHI盒子
!实时搜索: 盒子论坛 | 注册用户 | 修改信息 | 退出
检举帖 | 全文检索 | 关闭广告 | 捐赠
技术论坛
 用户名
 密  码
自动登陆(30天有效)
忘了密码
≡技术区≡
DELPHI技术
lazarus/fpc/Free Pascal
移动应用开发
Web应用开发
数据库专区
报表专区
网络通讯
开源项目
论坛精华贴
≡发布区≡
发布代码
发布控件
文档资料
经典工具
≡事务区≡
网站意见
盒子之家
招聘应聘
信息交换
论坛信息
最新加入: shz0000
今日帖子: 34
在线用户: 15
导航: 论坛 -> DELPHI技术 斑竹:liumazi,sephil  
作者:
男 guistory (鬼故事) ▲▲▲▲▲ -
普通会员
2017/5/28 17:16:58
标题:
大家帮我看看这段代码,为啥按下空格键会触发button2click呢? 浏览:1091
加入我的收藏
楼主: 如题,代码如下:

implementation
var
names:array of string;

procedure TForm1.Button2Click(Sender: TObject);
var
pmyfile:textfile;
pstr:string;
I: Integer;
begin
assignfile(pmyfile,'namexxx.txt')    ;
reset(pmyfile);
i:=0 ;

while not eof(pmyfile) do
begin
readln(pmyfile,pstr);
next;
i:=i+1;
end;
closefile(pmyfile);
setlength(names,i);
showmessage(inttostr(length(names)));


procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var
p:Tpoint;
begin
getcursorpos(p);
case Key of
vk_space:
    begin
      if rzbutton1.Caption = '按空格键开始抽取' then
         begin
         timer1.Enabled:=true;
         rzbutton1.Caption := '按空格键停止抽取' ;
         end
      else if (p.X >=500) and (rzbutton1.Caption = '按空格键停止抽取')  then
          begin
          timer1.Enabled :=false ;
          messagebox(0,PChar(rzdblabel1.Caption),'提示',MB_OK) ;
          rzbutton1.Caption := '按空格键开始抽取' ;
          end
          else   if (p.X <500) and (rzbutton1.Caption = '按空格键停止抽取')  then
          begin
          timer1.Enabled :=false ;
          rzdblabel1.Caption:='某公司,某人,111111';
          messagebox(0,PChar(rzdblabel1.Caption),'提示',MB_OK) ;
          rzbutton1.Caption := '按空格键开始抽取' ;
          end;

    end;
vk_f2: button2.Click;
vk_f1: button1.click;
end;


end;
----------------------------------------------
-
作者:
男 ying32 (唯有此生) ▲▲▲▲▲ -
普通会员
2017/5/28 19:38:52
1楼: 如果当前焦点在button2上,然后Form的KeyPreview不为true时肯定就会这样了,需要将keypreview设置为true,优先处理
----------------------------------------------
一个热爱delphi的人,Golang GUI库。 --我的博客--
作者:
男 guistory (鬼故事) ▲▲▲▲▲ -
普通会员
2017/5/31 8:54:26
2楼: 我现在Form的KeyPreview为true也出现这种状况
----------------------------------------------
-
作者:
男 beibeili (beibeili) ★☆☆☆☆ -
普通会员
2017/5/31 16:44:23
3楼: 你的代码中vk_space段中好像没有调用button2.click的代码呀!
是键入F2调用button2.click
----------------------------------------------
-
信息
登陆以后才能回复
Copyright © 2CCC.Com 盒子论坛 v3.0.1 版权所有 页面执行62.5毫秒 RSS