Recent

Author Topic: Is onDropFiles implemented?  (Read 15489 times)

JazzMan

  • New Member
  • *
  • Posts: 32
    • http://www.earmaster.com
Is onDropFiles implemented?
« on: October 08, 2008, 09:25:48 am »
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

  • New Member
  • *
  • Posts: 21
RE: Is onDropFiles implemented?
« Reply #1 on: October 08, 2008, 02:26:34 pm »
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

  • Hero Member
  • *****
  • Posts: 5706
    • Bart en Mariska's Webstek
RE: Is onDropFiles implemented?
« Reply #2 on: October 09, 2008, 11:21:05 am »
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

  • Hero Member
  • *****
  • Posts: 2737
Re: RE: Is onDropFiles implemented?
« Reply #3 on: October 09, 2008, 03:20:18 pm »
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

  • New Member
  • *
  • Posts: 32
    • http://www.earmaster.com
RE: Re: RE: Is onDropFiles implemented?
« Reply #4 on: October 10, 2008, 09:41:36 pm »
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

  • Hero Member
  • *****
  • Posts: 2737
Re: RE: Re: RE: Is onDropFiles implemented?
« Reply #5 on: October 11, 2008, 04:08:48 am »
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

  • New Member
  • *
  • Posts: 32
    • http://www.earmaster.com
Is onDropFiles implemented?
« Reply #6 on: October 13, 2008, 11:28:45 am »
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

  • Hero Member
  • *****
  • Posts: 2737
Is onDropFiles implemented?
« Reply #7 on: October 13, 2008, 06:27:24 pm »
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

  • New Member
  • *
  • Posts: 32
    • http://www.earmaster.com
Is onDropFiles implemented?
« Reply #8 on: October 15, 2008, 07:55:08 am »
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

  • New member
  • *
  • Posts: 9
Is onDropFiles implemented?
« Reply #9 on: October 16, 2008, 09:36:40 am »
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

  • New Member
  • *
  • Posts: 21
Is onDropFiles implemented?
« Reply #10 on: October 16, 2008, 02:14:03 pm »
Quote from: "geoffrey"

but not to files dropped on either of the forms.


That is still TODO.

Hansaplast

  • Hero Member
  • *****
  • Posts: 765
  • Tweaking4All.com
    • Tweaking4All
Re: Is onDropFiles implemented?
« Reply #11 on: January 10, 2011, 12:20:46 am »
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.

 

TinyPortal © 2005-2018