Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to trap the OnEnter and OnLeave events Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
22-Jun-03
Category
VCL-General
Language
Delphi 3.x
Views
70
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			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.


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC