Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

TButton::OnClick delete Sender

1 view
Skip to first unread message

Remy Lebeau (TeamB)

unread,
Dec 4, 2003, 10:39:40 PM12/4/03
to

"JunkMail" <Per...@Hotmail.com> wrote in message
news:3fcffa28$1...@newsgroups.borland.com...
> I'm getting an access violation error I'm wondering if
> its even legal to do something like this

It is not legal to do that, no. You should never 'delete' a component from
its own event handlers. The AV is coming from the VCL trying to access the
button again after the event handler returns. You deleted the memory, so
the memory cannot be accessed anymore, so the AV occurs.

> Basically I have a delete button, a TUpDown object and a label...
> All have the same Top position...when the user clicks the delete
> button I want to delete that row of objects and then reposition
> the rest.

For something like that, I would suggest placing the controls onto either a
TPanel or a TFrame to keep them grouped together, and then when you click
the Delete button, post a custom message to the form containing a pointer to
the TPanel or TFrame and let the form delete it when nothing else is
happening with them. For example:

#define APPWM_DELETE_PANEL (WM_APP + 100)

void __fastcall TfrmFileDockSite::WndProc(TMessage &Message)
{
if( Message.Msg == APPWM_DELETE_PANEL )
{
delete reinterpret_cast<TPanel*>(Message.LParam);
Message.Result = TRUE;
}
else
TForm::WndProc(Message);
}

void __fastcall TfrmFileDockSite::btnDeleteClick(TObject *Sender)
{
TButton* btn = dynamic_cast<TButton*>(Sender);
if( btn )
{
TPanel *pnl = dynamic_cast<TPanel*>(btn->Parent);
if( pnl )
PostMessage(Handle, APPWM_DELETE_PANEL, 0,
reinterpret_cast<LPARAM>(pnl));
}
}


Gambit

JunkMail

unread,
Dec 4, 2003, 10:23:22 PM12/4/03
to
I'm getting an access violation error I'm wondering if its even legal to do
something like this

void __fastcall TfrmFileDockSite::btnDeleteClick(TObject *Sender)


{
TButton* btn = dynamic_cast<TButton*>(Sender);

//delete some labels and other stuff
//...
delete btn; //is this ok to do?

Junk Mail

unread,
Dec 5, 2003, 1:05:15 AM12/5/03
to
is WndProc suppose to be public, protected, or private? I'm sure its one of
the first 2. I looked in the help file for TCustomForm::WndProc but it
doesn't say.


Remy Lebeau (TeamB)

unread,
Dec 5, 2003, 1:44:45 AM12/5/03
to

"Junk Mail" <Junk...@GlobalWideCommunications.com> wrote in message
news:3fd0200f$1...@newsgroups.borland.com...

> is WndProc suppose to be public, protected, or private?

It doesn't really matter. Technically, it is declared as 'protected' in
TWinControl and most descendants, but it is not required to be so. Some
people declare it as 'public' and some declare it as 'private'. It works
either way. Personally, I would suggest keeping it 'protected'.


Gambit


0 new messages