In Delphi XE can I allow my form to accept file ‘drag and drop’ but without having to handle bare windows messages?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You don’t need to handle messages to implement this. You just need to implement
IDropTargetand callRegisterDragDrop/RevokeDragDrop. It’s really very very simple. You can actually implementIDropTargetin your form code but I prefer to do it in a helper class that looks like this:The idea here is to wrap up the complexity of the Windows
IDropTargetinTDropTarget. All you need to do is to implementIDragDropwhich is much simpler. Anyway, I think this should get you going.Create the drop target object from your control’s
CreateWnd. Destroy it in theDestroyWndmethod. That point is important because VCL window re-creation means that a control can have its window handle destroyed and re-created during its lifetime.Note that reference counting on
TDropTargetis suppressed. That is because whenRegisterDragDropis called it increments the reference count. This creates a circular reference and this code to suppress reference counting breaks that. This means that you would use this class through a class variable rather than an interface variable, in order to avoid leaking.The usage would look something like this:
Here I am using a form as the drop target. But you could use any other windowed control in a similar fashion.