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

drag&drop

0 views
Skip to first unread message

Marek Konitz

unread,
Mar 17, 2003, 9:32:47 AM3/17/03
to
Hi,

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

Ralph Kazemier

unread,
Mar 17, 2003, 12:03:46 PM3/17/03
to

"Marek Konitz" <mar...@simtel.pl> wrote in message
news:fumb7vgad4adj5mc3...@4ax.com...

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


Mike Knoblock

unread,
Mar 17, 2003, 4:53:46 PM3/17/03
to
This is happening because the VCL calls EndDrag() for the 'Source' component
after the OnDragDrop event for the 'Target'. Try using your EndDrag event
to start a short Timer that deletes the source component.


"Marek Konitz" <mar...@simtel.pl> wrote in message
news:fumb7vgad4adj5mc3...@4ax.com...

0 new messages