I want to destroy dropped object in OnDragDrop procedure:
void __fastcall TForm1::Panel1DragDrop(TObject *Sender,
TObject *Source, int X, int Y)
{
delete Source;
}
but it causes AccesViolation.
Does anyone know how to do it correctly?
Marek
The OnDragDrop eventhandler is actually called because Windows has sent a
message to a certain window in your application. Apparently the 'Source' is
still referred to (inside the VCL) when the message handling returns from
your event handler. So you can't delete it right away. You can only safely
delete the component after the message is handled, not during that process.
So what you need to do is post a message to 'yourself' and delete the
component there. A simple way to do this; send your form a custom message
and handle it by overriding your form's WndProc();
#define CM_DELETE_COMPONENT WM_USER+0x01
void __fastcall TForm1::Panel1DragDrop(
TObject *Sender,
TObject *Source,
int X, int Y)
{
PostMessage(
Handle,
CM_DELETE_COMPONENT,
(WPARAM)Source,
0
);
}
void __fastcall TForm1::WndProc(Messages::TMessage &Message)
{
if(Message.Msg == CM_DELETE_COMPONENT)
{
delete ((TObject*)Msg.WParam);
}
else
{
TForm::WndProc(Message);
}
}
Ralph
"Marek Konitz" <mar...@simtel.pl> wrote in message
news:fumb7vgad4adj5mc3...@4ax.com...