Author: Christer Johansson This code shows how to get the OnEnter and OnLeave event from components without changing the component. Answer: 1 unit Unit1; 2 3 interface 4 5 uses 6 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, 7 StdCtrls; 8 9 type 10 TForm1 = class(TForm) 11 Label1: TLabel; 12 Button1: TButton; 13 procedure FormCreate(Sender: TObject); 14 procedure FormDestroy(Sender: TObject); 15 private 16 { Private declarations } 17 FFocusControl: TControl; 18 procedure ApplicationIdle(Sender: TObject; var Done: Boolean); 19 public 20 { Public declarations } 21 procedure OnEnter(Sender: TObject); 22 procedure OnExit(Sender: TObject); 23 end; 24 25 var 26 Form1: TForm1; 27 28 implementation 29 30 {$R *.DFM} 31 32 procedure TForm1.FormCreate(Sender: TObject); 33 begin 34 FFocusControl := nil; 35 Application.OnIdle := ApplicationIdle; 36 end; 37 38 procedure TForm1.FormDestroy(Sender: TObject); 39 begin 40 Application.OnIdle := nil; 41 end; 42 43 procedure TForm1.ApplicationIdle(Sender: TObject; var Done: Boolean); 44 var 45 CurControl: TControl; 46 P: TPoint; 47 begin 48 GetCursorPos(P); 49 CurControl := FindDragTarget(P, True); 50 if FFocusControl <> CurControl then 51 begin 52 if FFocusControl <> nil then 53 OnExit(FFocusControl); 54 FFocusControl := CurControl; 55 if FFocusControl <> nil then 56 OnEnter(FFocusControl); 57 end; 58 end; 59 60 procedure TForm1.OnEnter(Sender: TObject); 61 begin 62 //OnEnter code 63 if sender = Button1 then 64 begin 65 Label1.caption := 'Hello'; 66 Button1.Caption := 'Exit'; 67 end; 68 end; 69 70 procedure TForm1.OnExit(Sender: TObject); 71 begin 72 //OnExit code 73 if sender = Button1 then 74 begin 75 Label1.caption := 'Godbye'; 76 Button1.Caption := 'Enter'; 77 end; 78 end; 79 80 end.