Drag and Drop files into the form
Some of you, or I would say, 90% of you need to drag files into your applications. Whether you are creating an audio or video player. A picture viewer or could be anything, drag and drop is a nice feature for an application to have. Well in this post I am going to show you how drag and drop works and how you can get this working.
First let's go to the code and we will analyze it after.
You need to add ShellApi to your uses at the top of the unit. And also set the property DragMode of your form to Automatic (this permits the application to automatically detect when something is getting dragged into your app)
Form OnCreateEvent
DragAcceptFiles(Handle,TRUE);
This allows your application to accept dragged files. If you set this to false you will see that when you try to drag something into your application, it will change the drag icon and it doesn't let you drag on it.
In the above code I am using a TMemo, whatever I drag into the application the form will open it. Of course if you drag a video or something that is not compatible with text format it will not open it. What this code does is that it creates an array for you, from 0 to the Max value of the path. The other calls are internal functions, you need to know how to use them, just take note of it and try to memorize them. It can help you later on in the future.
In your private section:
procedure DropFiles(var Msg: TWMDropFiles); message WM_DROPFILES;
This is the procedure, it uses functions that work with Delphi, I don't want to confuse you. That TWMDropFiles is a message call.
That is the whole code part. Now let me brake down some stuff for you to understand.
Further informations in German can be found here.