Recent

Author Topic: OnDropFiles works on Windows but not on Mac  (Read 3094 times)

Benoni_Edin

  • Newbie
  • Posts: 5
OnDropFiles works on Windows but not on Mac
« on: August 01, 2017, 06:41:51 pm »
I've developed an application that works perfectly on Windows and Mac except for one thing: Dropping files on a form doesn't work on Mac, i.e., the OnDropFiles is never activated.

This bug has been reported to be fixed (https://bugs.freepascal.org/view.php?id=18486) in 2015 or earlier. In my case, however, it doesn't work when files from Finder are dropped even on the "Dock icon".

I use exactly the same code for Windows and Mac (which is amazing for someone previously fighting with Delphi) and haven't experienced any problems with any other parts of the code (which is rather extensive and takes advantage of a lot of  fpc features).

I'm running Mac OS X, 10.7.5 (I haven't tested file dropping on Sierra but everything else in the program is known to work exactly as on Lion).

This is reported by my Lazarus installation (on Mac):
  Lazarus version #: 1.6.4
  FPC version: 3.0.2
  i386-darwin-carbon

Any suggestions?

/Ben

Phil

  • Hero Member
  • *****
  • Posts: 2737
Re: OnDropFiles works on Windows but not on Mac
« Reply #1 on: August 01, 2017, 07:23:59 pm »
I've developed an application that works perfectly on Windows and Mac except for one thing: Dropping files on a form doesn't work on Mac, i.e., the OnDropFiles is never activated.

That works fine here with the Carbon widgetset, both dropping a file on the running app's main window, as well as dropping it on running app on the Dock, as well as just dropping the file on the app in Finder. With the Cocoa widgetset, dropping on the main window does not yet work, but the other two methods do.

When you double-click on of your app's files in Finder, does the app start and open the file? If not, then you either don't have the OnDropFiles event property set or you don't have the file association set up in the app's Info.plist file.

I would strongly suggest that you upgrade your OS X, at least to 10.10.

Benoni_Edin

  • Newbie
  • Posts: 5
Re: OnDropFiles works on Windows but not on Mac
« Reply #2 on: August 02, 2017, 09:08:32 pm »
PROBLEM SOLVED:

The issue wasn't MacOS 10.7 per se and the problem wasn't due to a bug. Windows and MacOS handle the OnDropFiles event differently.

In my program it wasn't the main form that was supposed to manage the OnDropFiles event but a modal form that was activated from the main form by the user.

This works fine in Window, i.e., the Main form probably automatically passes on the event to the modal window. With MacOS this doesn't happen (at least with MacOS 10.7).

To solve this - and making file dropping work as intended on both Windows and MacOS - one needs to set AllowDropFiles to TRUE on the Main form and then to add an OnDropFiles procedure to the Main form, e.g., as follows
Code: Pascal  [Select][+][-]
  1. procedure TMainForm.FormDropFiles(Sender: TObject;
  2.   const FileNames: array of String);
  3. begin
  4.   if MyModalForm.Showing then MyModalForm.FormDropFiles(Sender, FileNames);
  5. end;

In short, the solution was to make the main form simply pass on the event to the modal form but only if the latter is active/showing (btw, the MyModalForm is auto-created).

To the best of my knowledge, this solution doesn't create any troublesome side-effects. 


 

TinyPortal © 2005-2018