1
votes

I'm a Delphi-programmer and I have a question. I create a form with TStyleManager and I use skins on my application. But I want to use Drag-n-Drop files in my app too. How I can realize this? I have tried many methods, but ... I could not get to do it. Hope on your help

3
How did you try it? What are the symptoms? Did you set the main form's DockSite property to true? What happens in the OnDockOver and OnDockDrop events?Attila Fulop
For a general drag-n-Drop solution see Drag/Drop inside an Application AND to another Application. Please elaborate what your specific problem with styles and drag-n-Drop is.LU RD

3 Answers

5
votes

When you change the vcl style the handle of the form is recreated, so if you call the DragAcceptFiles function before to set the style the handle used will not be the same when the style is applied. To fix that execute the DragAcceptFiles function in this way.

 TStyleManager.SetStyle(StyleName);
 Application.ProcessMessages;//process the message queue;
 DragAcceptFiles( Handle, True );
0
votes

use shellApi unit's method DragAcceptFiles to achieve what you need . It needs 2 parameter , first is the handle of the Application and second a boolean to specify whether to switch on - off drag feature . to turn on use something like DragAcceptFiles(Self.Handle,True);

To respond to drag and drop of files , use

Procedure TForm1.RespondToMessage(var Msg : TMsg;var handled : Boolean) ;
const
   FileIndex : Cardinal = Cardinal(-1);   { return a count of dropped files }
   BuffLen   = 255;
 Var
    FileNum : Word;
   FName : String;
   BuffArr : Array[0..MAX_PATH-1] of Char;
 Begin
If Msg.message = WM_DROPFILES Then
 Begin

For FileNum := 0 To DragQueryFile(Msg.wParam,FileIndex,Nil,BuffLen)-1 Do   // first time , FileIndex is 0xFFFFFFFF , so
// the return is the number of files to be dragged
// Here the return in fileIndex is the no of files;
Begin
   DragQueryFile(Msg.wParam, FileNum , BuffArr , BuffLen);
   FName := StrPas(BuffArr);
   //AddButton(FName); -- do whatever operation you want with the fileName
End;
Try
  DragFinish(Msg.wParam);  // Free the memory given to drag operation
Except
End;  
Handled := True;
//AddScrollIfRequired;
End;
End;

Now include Application.OnMessage := RespondToMessage to trap the drag & drop operations. Hope that helps

0
votes

That code below causes Access violation on COMCTL32.dll module. How to fix that please? i use Delphi 10.4**

procedure TForm1.StylesListSelect(Sender: TObject);
begin
   try
    if Assigned(TStyleManager.ActiveStyle) then
  TStyleManager.TrySetStyle(TStyleManager.StyleNames[StylesList.ItemIndex]);

    Application.ProcessMessages;  // it breaks here
    DragAcceptFiles(WindowHandle, True);
   except
   end;
end;