好像是Delphi5.5的一个bug,问题如下:在主窗口form1上放一个edit1和一个edit2。在edit1的onKeyDown事件下写入如下代码:
procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if key=13 then edit2.SetFocus;
end;在edit1的onExit事件下写入如下代码:
procedure TForm1.Edit1Exit(Sender: TObject);
begin
  if strtoint(edit1.text)>4 then
    application.MessageBox('输入的数值大于5!','提示',mb_ok);
end;执行这个程序,在edit1中输入数值7,然后按回车键,跳出提示框“输入的数值大于5!”,这时正常情况光标应该在edit2上,可你会发现edit2上没有闪烁的光标,用鼠标点击也不行。但可以输入数值。把application.MessageBox换成showmessage或messagedlg,没有这种情况,但如果在edit1输入数值后不按回车键,而是用鼠标点击edit2时,左右动一动鼠标,你又会发现新问题!!!不知道有没有DELPHI顶尖高手可以解释这个问题,给出解决方法!!!

解决方案 »

  1.   

    你刚将焦点移动到edit2就弹出了对话框,这样焦点自然又被转移了。
      

  2.   

    晕,这也能叫bug
    是你写的不好
      

  3.   

    各位最好拿真正的程序先试一试再发言,别丢人现眼!!!把上面程序edit1的onExit事件下的代码改成如下,再执行,看看报的错误吧!:
    procedure TForm1.Edit1Exit(Sender: TObject);
    begin
      if strtoint(edit1.text)>4 then
      begin
        application.MessageBox('输入的数值大于5!','提示',mb_ok);
        edit2.setfocus;
      end;
    end;我试过了,调用windows的api函数显示信息,没有上面的问题!
    靠,这也不算bug!?那泰森就不咬人耳朵了!!!
      

  4.   

    没用过什么delphi5.5,在d7中一切正常。
      

  5.   

    Delphi6和7中没有这个问题!但Delphi5.5我打了补丁也出现这个错误!
    虽然Delphi8都出来了!但全都试过以后,还是决定用Delphi5.5。
    吕方的《老情歌》中不是唱过:......情歌总是老的好,走遍天涯海角忘不了.....
      

  6.   

    我用的是正版Delphi5.5,如果谁用盗版的,执行上面的程序没出错!那就是正版的有BUG,而盗版的已经修正了!那我以后就放弃不好用的正版,只用盗版!就算是清华大学毕业的,也未必都能是天才;
    就算是没念过大学的,也未必不能编制出经典的好软件!不怕不懂,因为可以永远的学下去!
    就怕不懂装懂,以为自己会编个“Hello World!",就可以随意批判任何人!
      

  7.   

    DELPHI7+WIN2000SERVER测试无此问题楼主何必那么认真呢,现在又有几个人还用DELPHI5.5呢?
      

  8.   

    还有这不是什么BUG,可能是你的系统有问题,建议不要小题大作。
      

  9.   

    solokey(风语花开-永远的菜鸟)兄说的有理,如今还有几个人,还在使用Delphi6以前的版本.....
    我知道6和7都没有这个问题,以后的8也更不会有,但在5中就是有!而且不是程序编制问题,而是Delphi问题。如果楼上各位非要说是我程序编制有问题,那请问为何用相同的程序6和7没有问题呢!!!最好的矛碰到最好的盾了吧!!!
      

  10.   

    D7中没问题D5中真的有问题,可能的确有点问题吧?不过算BUG?
      

  11.   

    我找到了!!D5 中 function TApplication.MessageBox(const Text, Caption: PChar; Flags: Longint): Integer;
    var
      ActiveWindow: HWnd;
      WindowList: Pointer;
      MBMonitor, AppMonitor: HMonitor;
      MonInfo: TMonitorInfo;
      Rect: TRect;
    begin
      ActiveWindow := GetActiveWindow;
      MBMonitor := MonitorFromWindow(ActiveWindow, MONITOR_DEFAULTTONEAREST);
      AppMonitor := MonitorFromWindow(Handle, MONITOR_DEFAULTTONEAREST);
      if MBMonitor <> AppMonitor then
      begin
        MonInfo.cbSize := Sizeof(TMonitorInfo);
        GetMonitorInfo(MBMonitor, @MonInfo);
        GetWindowRect(Handle, Rect);
        SetWindowPos(Handle, 0,
          MonInfo.rcMonitor.Left + ((MonInfo.rcMonitor.Right - MonInfo.rcMonitor.Left) div 2),
          MonInfo.rcMonitor.Top + ((MonInfo.rcMonitor.Bottom - MonInfo.rcMonitor.Top) div 2),
          0, 0, SWP_NOACTIVATE or SWP_NOREDRAW or SWP_NOSIZE or SWP_NOZORDER);
      end;
      WindowList := DisableTaskWindows(0);
      if UseRightToLeftReading then Flags := Flags or MB_RTLREADING;
      try
        Result := Windows.MessageBox(Handle, Text, Caption, Flags);
      finally
        if MBMonitor <> AppMonitor then
          SetWindowPos(Handle, 0,
            Rect.Left + ((Rect.Right - Rect.Left) div 2),
            Rect.Top + ((Rect.Bottom - Rect.Top) div 2),
            0, 0, SWP_NOACTIVATE or SWP_NOREDRAW or SWP_NOSIZE or SWP_NOZORDER);
        EnableTaskWindows(WindowList);
        SetActiveWindow(ActiveWindow);
      end;
    end;D7 中
    function TApplication.MessageBox(const Text, Caption: PChar; Flags: Longint): Integer;
    var
      ActiveWindow: HWnd;
      WindowList: Pointer;
      MBMonitor, AppMonitor: HMonitor;
      MonInfo: TMonitorInfo;
      Rect: TRect;
      FocusState: TFocusState;
    begin
      ActiveWindow := GetActiveWindow;
      MBMonitor := MonitorFromWindow(ActiveWindow, MONITOR_DEFAULTTONEAREST);
      AppMonitor := MonitorFromWindow(Handle, MONITOR_DEFAULTTONEAREST);
      if MBMonitor <> AppMonitor then
      begin
        MonInfo.cbSize := Sizeof(TMonitorInfo);
        GetMonitorInfo(MBMonitor, @MonInfo);
        GetWindowRect(Handle, Rect);
        SetWindowPos(Handle, 0,
          MonInfo.rcMonitor.Left + ((MonInfo.rcMonitor.Right - MonInfo.rcMonitor.Left) div 2),
          MonInfo.rcMonitor.Top + ((MonInfo.rcMonitor.Bottom - MonInfo.rcMonitor.Top) div 2),
          0, 0, SWP_NOACTIVATE or SWP_NOREDRAW or SWP_NOSIZE or SWP_NOZORDER);
      end;
      WindowList := DisableTaskWindows(0);
      FocusState := SaveFocusState;
      if UseRightToLeftReading then Flags := Flags or MB_RTLREADING;
      try
        Result := Windows.MessageBox(Handle, Text, Caption, Flags);
      finally
        if MBMonitor <> AppMonitor then
          SetWindowPos(Handle, 0,
            Rect.Left + ((Rect.Right - Rect.Left) div 2),
            Rect.Top + ((Rect.Bottom - Rect.Top) div 2),
            0, 0, SWP_NOACTIVATE or SWP_NOREDRAW or SWP_NOSIZE or SWP_NOZORDER);
        EnableTaskWindows(WindowList);
        SetActiveWindow(ActiveWindow);
        RestoreFocusState(FocusState);
      end;
    end;不知道大家注意了没有,看最后一行D7中多了  RestoreFocusState(FocusState);将焦点恢复了回来!!!的确D5中存在这个问题!!!
      

  12.   

    我就那也应该是VCL的小BUG吧。。再说还有几个人用5.5了?
      

  13.   

    codehunter008(代码猎手008),感谢你用真正的技术为我解释了这个问题!我心服口服!!!
    不象别的人,说什么对Delhpi5不感兴趣……、说什么系统的错或是我编制的程序问题……
    更有甚者,以为自己多穿几条内裤,就有多了不起!我已经改了我编制的程序,用其它方式实现上述功能,避免了上面出现的问题,但我只是想知道为什么会有这个错误?
    如果有谁告诉我一件事这样做是错的,那样做才对,我不会简单的照着他说的去做,我会弄清楚原因是什么!我知道应该不断的向前发展,所以现在的人多也在不断的去追求新的东西。
    可我只是个山里的孩子,家里穷,买不起昂贵的Delphi6或更高的7和8,所以我一直在使用曾祖父留下的Delphi5,
    因为幼儿园没能毕业,所以我只能靠仅仅会的汉语拼音试着编程,为了养家户口,我只能在出外放猪的时候编编小程序,
    用来帮像中国×信这样的小公司管管用户通话计费。可因为我没学过数学,不懂为什么一分钟有57秒,所以不久就丢了这份工作。
    现在只能帮家×福这样的小卖店编卖货程序……
    日子就这样淡淡的过着…………
      

  14.   

    Delphi.net网上都可以下载了
    不用钱的,呵呵
      

  15.   

    下载不了,因为我很穷,上不起宽带,现在只能用NOKIA 9210c手机无线上网.......^_^
      

  16.   

    to goodsung(凄风冷雨):“不懂为什么一分钟有57秒”,这是发财的秘密啊。