unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Button1: TButton;
    Button2: TButton;
    procedure Edit1Exit(Sender: TObject);
    procedure Button1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure FormCreate(Sender: TObject);
    procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  Form1: TForm1;
  tt : Boolean ;
implementation{$R *.dfm}procedure TForm1.Edit1Exit(Sender: TObject);
begin
    if not tt then 
      showmessage('ok')
end;procedure TForm1.Button1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
   tt := true ;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
tt:=false ;
end;procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
   tt := false ;
end;end.
/////pas文件
object Form1: TForm1
  Left = 192
  Top = 114
  Width = 544
  Height = 375
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  OnCreate = FormCreate
  OnMouseMove = FormMouseMove
  PixelsPerInch = 96
  TextHeight = 13
  object Edit1: TEdit
    Left = 40
    Top = 112
    Width = 121
    Height = 21
    TabOrder = 0
    Text = 'Edit1'
    OnExit = Edit1Exit
  end
  object Button1: TButton
    Left = 224
    Top = 120
    Width = 75
    Height = 25
    Caption = 'Button1'
    TabOrder = 1
    OnMouseMove = Button1MouseMove
  end
  object Button2: TButton
    Left = 328
    Top = 128
    Width = 75
    Height = 25
    Caption = 'Button2'
    TabOrder = 2
  end
end///窗体文件

解决方案 »

  1.   

    的确,如果用键盘来做,有很大的问题。为什么要屏蔽onexit事件了?在这个事件中作了什么事?保存数据?说说你为什么要这样做,或许有其他办法
      

  2.   

    我只是在OnExit时校验其中的内容,我觉得点Cancel时不用,就想屏蔽了
      

  3.   

    点Cancel就将edit中的内容清空?
    校验什么。看他是否合法数据?
    可以在edit.onchange中做呀
      

  4.   

    取消的事件用onexit代替onexit里if sender is edit thenelse
    if sender is buttoncancel then
      

  5.   

    在edit.onchange中做太麻烦,我想到一种:
      在OnExit中: 
       if TWinControl(Screen.ActiveControl).Name <> 'bbtnCancel' then
         ....
      

  6.   

    最简单的方法:
    不在OnExit中校验,在你处理数据之前校验即可。
      

  7.   

    可以用个布尔变量来判断,如果布尔变量为真,则认为被按了CANCLE键,在ONExit过程中,根据布尔变量的值进行操作。