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 Implement the equivalent of TForm.OnCreate for a TFrame 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
27-Mar-03
Category
VCL-General
Language
Delphi 5.x
Views
99
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Lou Adler

I miss one thing in frames: The ability of performing some initialization code as I 
would do in a TForm.OnCreate. So what would be the equivalent for frames?

Answer:

You can override the constructor for example. An alternative is to override the 
SetParent method and do the initialization after calling the inherited method. This 
way the frame will have a parent and you can then do things that require a window 
handle without running into problems. I use a base frame class in my current 
project that has this feature build in. The relevant parts are given below. In 
descendents I just override the Initialize method.

1   { ... }
2   type
3     {The base class for frames}
4     TPLC_BaseFrame = class(TFrame)
5     protected
6       procedure SetParent(aParent: TWinControl); override;
7     public
8       procedure Initialize; virtual;
9       procedure UnInitialize; virtual;
10      destructor Destroy; override;
11    end;
12  
13  procedure TPLC_BaseFrame.Initialize;
14  begin
15    {Override as needed in descendents}
16  end;
17  
18  procedure TPLC_BaseFrame.UnInitialize;
19  begin
20    {Override as needed in descendents}
21  end;
22  
23  procedure TPLC_BaseFrame.SetParent(aParent: TWinControl);
24  var
25    oldparent: TWinControl;
26  begin
27    oldparent := Parent;
28    inherited;
29    if (oldparent = nil) and (aParent <> nil) then
30      Initialize;
31  end;
32  
33  destructor TPLC_BaseFrame.Destroy;
34  begin
35    Uninitialize;
36    inherited;
37  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