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
Make a component execute a procedure every time the main form is activated 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
11-Feb-03
Category
VCL-General
Language
Delphi 2.x
Views
96
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jonas Bilinkevicius

I want my component to execute my procedure every time the main form gets 
activated. I don't want the main form to execute an event. The component should do 
it. It's a component I use in every application I write, and the procedure always 
does the same thing. So I just want to avoid adding the same routine over and over 
again in the main form. Even when it's just putting a TComponent.Execute in 
Form1.FormActivate. Is it possible?

Answer:

It can be non-visual component as well in that case. You can simply drop on a form 
the following component. In TActivateHook.FormActivate you put the code for all 
forms, if you want any special processing for particular form, you put that code 
into that form's OnActivate.

1   { ... }
2   type
3     TActivateHook = class(TComponent)
4     private
5       OldActivate: TNotifyEvent;
6       procedure FormActivate(Sender: TObject);
7     protected
8       procedure Loaded; override;
9     end;
10  
11    { TActivateHook }
12  
13  procedure TActivateHook.FormActivate(Sender: TObject);
14  begin
15    if Assigned(OldActivate) then
16      OldActivate(Sender);
17    {Put your code here}
18  end;
19  
20  procedure TActivateHook.Loaded;
21  begin
22    inherited;
23    if not (csDesigning in ComponentState) and (Owner <> nil) and
24      Owner.InheritsFrom(TForm) then
25    begin
26      OldActivate := TForm(Owner).OnActivate;
27      TForm(Owner).OnActivate := FormActivate;
28    end;
29  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