Board index » cppbuilder » TButton

TButton


2004-02-23 07:48:51 PM
cppbuilder0
When user click on button I have to delete it (together with some other
components). The problem is that access violation exception occures in
OnClick() procedure. I'm generating buttons (and other components) in run
time:
TButton *btn = new TButton(frm);
btn->OnClick = myOnClick;
Could this problem be solved?
TIA
 
 

Re:TButton

I think we need a bit more code here - please can you show *all* the code in
the OnClick procedure.
(Don't forget to set the Parent property of any controls created at runtime)
Rgds Pete
"Oliver Young" <none>wrote in message
Quote

When user click on button I have to delete it (together with some
other
components). The problem is that access violation exception occures in
OnClick() procedure. I'm generating buttons (and other components) in run
time:

TButton *btn = new TButton(frm);
btn->OnClick = myOnClick;
 

Re:TButton

"Oliver Young" <none>wrote:
Quote

When user click on button I have to delete it (together with some other
components). The problem is that access violation exception occures in
OnClick() procedure.
You can not delete an object from within it's own events.
Search this group for sending a custom message to be used to
delete the button.
~ JD
 

{smallsort}

Re:TButton

"JD" < XXXX@XXXXX.COM >wrote:
Quote
Search this group for sending a custom message to be used to
delete the button.
Look at this thread:
newsgroups.borland.com/cgi-bin/dnewsweb?utag=&group=borland.public.cppbuilder.vcl.components.using&xrelated=76117&cmd_related=Related+Items
It defines a custom message (You can change the definitions to
something more meaningful). Once defined, you simply post the
custom message which gives the event enough time to finish
execution and the the message handler does the actual deletion:
//-------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
PostMessage(Handle, APPWM_UPDATE_CBTEXT, UPDATE_CBTEXT_MAGIC_NUMBER, reinterpret_cast<int>( Sender ) );
}
//-------------------------------------------------------------void __fastcall TForm1::AppUpdateCBText(TWMUpdateText &Message)
{
if( Message.MagicNum == UPDATE_CBTEXT_MAGIC_NUMBER )
{
// cast Message.Sender to your button type
// do your deleting
Message.Result = TRUE;
}
else TForm::Dispatch(&Message);
}
//-------------------------------------------------------------
~ JD
 

Re:TButton

"Oliver Young" <none>wrote in message
Quote
When user click on button I have to delete it (together
with some other components).
You cannot delete the button while you are still inside its event handler.
You must delay the deletion until after the event handler returns, and
nothing else is accessing the button. Have a look at the following example:
tinyurl.com/3h8p7
aka
groups.google.com/groups
Gambit
 

Re:TButton

Again, this is easier if you use a timer object with an interval of 300ms,
disabled. When you want to delete the button, set the timer enabled to true.
In the timer event ontimer, delete the button.
--
Mark Jacobs
DK Computing
www.dkcomputing.co.uk
XXXX@XXXXX.COM
"Oliver Young" <none>wrote in message
Quote

When user click on button I have to delete it (together with some
other
components). The problem is that access violation exception occures in
OnClick() procedure. I'm generating buttons (and other components) in run
time:

TButton *btn = new TButton(frm);
btn->OnClick = myOnClick;

Could this problem be solved?

TIA


 

Re:TButton

How to change the color of TButton and make the cells of a TStringGrid multiline.
Thanks ALL,
Regards
Vikas
 

Re:TButton

"Vikas Sinha" < XXXX@XXXXX.COM >wrote in message
Quote
How to change the color of TButton
You don't. TButton does not support that. Use a different button
component, such as TSpeedButton. Or alternatively, use a TPanel and change
its Bevel properties in its OnMouseDown/Up events.
Quote
and make the cells of a TStringGrid multiline.
You need to over-draw the grid cells manually via the OnDrawCell event. You
can use the DrawText() function from the Win32 API to handle drawing text
with line breaks.
Gambit