Is onDropFiles implemented? lazarus / 15-macOS - Mac OS X ---------------------------------------------------------------------- JazzMan · 2008-10-08 07:25 In the roadmap it is tagged as "Partial implemented", but I cannot make it work. I have a file type registered in Info.plist and it works: when I double-click this file, it opens my application. I can however not get information about the filename that initiated the application launch. The onDropFiles event should do that according to the description, but it never gets fired. I use SVN revision 16907. Any hints? Best regards, Hans ---------------------------------------------------------------------- Tombo · 2008-10-08 12:26 Can you try DropFiles example app from lazarus/examples/dropfiles? Also Lazarus has ability to open files, if you drop them on dock icon. ---------------------------------------------------------------------- Bart · 2008-10-09 09:21 Maybe I do not understand your situation correctly, but I guess that onDropFiles is used if you drop a file on your running application. Double-clicking a filename, associated with your app, wil open the app with the filename in ParamStr(1) (at least on windows platform). Bart ---------------------------------------------------------------------- Phil · 2008-10-09 13:20 Quote from: "Bart"Maybe I do not understand your situation correctly, but I guess that onDropFiles is used if you drop a file on your running application. Double-clicking a filename, associated with your app, wil open the app with the filename in ParamStr(1) (at least on windows platform). Bart No, the double-clicked file's name is not passed via command line with OS X. The form's OnDropFile event works fine. To handle double-clicked files in a cross-platform way: - In startup code: {$IFNDEF DARWIN}   if ParamStr(1) <> '' then     do something with ParamStr(1) {$ENDIF} - If you want to ensure that drop files only used on OS X: {$IFDEF DARWIN} procedure TMainForm.DropFiles(      Sender    : TObject;                               const FileNames : array of string); begin   if High(FileNames) >= 0 then  {At least one file passed?}     do something with FileNames[0] end; {$ENDIF}                       Thanks. -Phil ---------------------------------------------------------------------- JazzMan · 2008-10-10 19:41 I tried the Dropfiles example. It works when I drag a file to the dock, though it doesn't allow me to drag a file into the form (which I don't need anyway). I have made my own application in the same way: - added a tApplicationProperties to the mainform - added an OnDropFiles event with showmessage(Filenames[0]) in both the MainForm and Application properties - Set the AllowDropFiles to true When I drag a file to the dock, the application runs, but none of the events are fired. Any suggestions? Best regards, Hans ---------------------------------------------------------------------- Phil · 2008-10-11 02:08 Quote from: "JazzMan"When I drag a file to the dock, the application runs, but none of the events are fired. No problems here. With the OnDropFiles handler above, I can do the following: - Double-click file. App starts and loads file. - App on Dock but not running. Dragging file to app on Dock starts app and loads file. - App on Dock and running. Dragging file to app loads file. I'm not using the application properties, on the form's. Thanks. -Phil ---------------------------------------------------------------------- JazzMan · 2008-10-13 09:28 That is strange. This indicates that my main form is not considered to be the main form by Lazarus? However, this is a large and complex application. There are about 50 forms and the project is shared between Windows/Delphi and Carbon/Lazarus. There are also other form beings created before the Mainform in this way: TempForm := TTempForm.Create(Application) Application.Createform(MyMainForm) When I test Application.mainform it is still equal to MyMainForm, even when creating the other form first. But even when I add the dropfiles event to both forms, nothing happens. In the Dropfile test program I tried to also create the second form before the mainform, in the same way as I do it in my application, but here it works. I can drop a file to the dock and it reports the filename. PS. When I double-click the OnDropFiles event in the object inspector. Lazarus crashes, so I assign the event dynamically. Maybe this is related to the problem? Best regards, Hans ---------------------------------------------------------------------- Phil · 2008-10-13 16:27 Quote from: "JazzMan"PS. When I double-click the OnDropFiles event in the object inspector. Lazarus crashes, so I assign the event dynamically. Maybe this is related to the problem? I'm assigning in code in my app too: {$IFDEF DARWIN}   OnDropFiles := DropFiles; {$ENDIF} This is in my TMainForm.FormCreate handler. If you can create a small example app that demonstrates the problem, please post it to the Mantis bug tracker. Thanks. -Phil ---------------------------------------------------------------------- JazzMan · 2008-10-15 05:55 It works in the example, but not in my main application. The 100.000 lines application is not suitable to submit in Mantis, but I'll post a bug if I am able to reproduce it in a smaller program, or I'll let you know if I solve it. Best regards, Hans ---------------------------------------------------------------------- geoffrey · 2008-10-16 07:36 I am using fpc 2.2.2 and laz 0.9.26 on an intel mac running 10.5.5 I have tried the dropfiles example. It responds to files dropped on the icon in the dock but not to files dropped on either of the forms. rgds, G ---------------------------------------------------------------------- Tombo · 2008-10-16 12:14 Quote from: "geoffrey" but not to files dropped on either of the forms. That is still TODO. ---------------------------------------------------------------------- Hansaplast · 2011-01-09 23:20 This problem still seems to exist, does anyone know if a bug has been reported? (see my posting) Sorry for the cross posting, I'm trying to avoid that I'm reporting a bug while there already might be one, and I haven't figured out (yet) how to search in Mantis.