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 delete a TFrame together with its parent TTabSheet 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-Aug-02
Category
VCL-General
Language
Delphi 5.x
Views
110
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

I have a form with a page control, and each tab sheet of the page control contains 
a frame. I would like to delete the frame along with the parent tab sheet if the 
user clicks a certain button on the frame. What's the best way to do this? It seems 
that if the tab sheet's free method is called from inside the button-click event 
handler, the button will be freed before the event handler is finished executing.

Answer:

The way to solve this is do like TCustomform.Release does it: post (via 
PostMessage) a user message to the form, have the form free the component in 
response to the message.

1   const
2     UM_DESTROYCONTROL = WM_USER + 230;
3   
4     {in form declaration}
5     private
6       { Private declarations }
7   
8   procedure UmDestroyControl(var msg: TMessage); message UM_DESTROYCONTROL;
9   
10  {in the buttons OnClick handler}
11  
12  var
13    ctrl: TWinControl;
14  begin
15    ctrl := GetParentForm(Sender as TButton);
16    PostMessage(ctrl.handle, UM_DESTROYCONTROL, 0, Integer(Sender));
17    { ... }
18  
19  procedure TForm1.UmDestroyControl(var msg: TMessage);
20  begin
21    TObject(msg.lparam).Free;
22  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