Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2009-10

Carbon: Loosing kAEOpenDocuments AppleEvents before AppRun

17 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

EarMaster - Bent Olsen

I might add that this also happens when you call CreateForm for two or more forms, where you call ShowModal (as in a user login form) before the first/main form is showing.

The ShowModal calls AppProcessMessages, and hence the events disappears before TApplicationProperties on the main form gets these.

Best regards,
Normann

Show quoted text 54 lines
-----Original Message----- From: EarMaster - Bent Olsen [mailto:] Sent: 28. oktober 2009 14:06 To: ' Subject: Carbon: Loosing kAEOpenDocuments AppleEvents before AppRun Hi, I came across a problem when using TApplicationProperties and waiting for OnDropFiles to be called. In a normal Application Initialize, CreateForm, and Run, the OnDropFiles event is fired, but if something happens in between Initialize and Run (like multiple CreateForms with a couple of controls "badly" calling ProcessMessages, or something else causing messages being released), before AppRun sets up an event handler, the OnDropFiles event is not fired - likely because the kAEOpenDocuments message has been released way before. You can check this by creating a new application, put a TApplicationProperties on Form1, assign OnDropFiles to a procedure which just sets the forms caption to FileNames[0], and in the project source code: ... Application.Initialize; Application.CreateForm(TForm1, Form1); Application.ProcessMessages; Application.Run; You need to create a shortcut to the compiled application on your Mac Dock, and drag any file on to it - the application should execute, when it is not running, and give you the name of the file in Form1's caption. The OnDropFiles doesn't fire (that is, if the application wasn't running and was being executed), but comment out the ProcessMessage and the OnDropFiles works fine. This might be a normal behavior for ProcessMessages to release unhandled messages, but I wish ProcessMessages could skip if no global event handler is set, so it is unfortunate TApplicationProperties is not receiving these messages. I'm not using ProcessMessages in the creating process in my application, but some controls are doing this internally, making it impossible to get OnDropFiles fired. Any tips? I could create the MainForm first, and create the other forms in an event after Run, but why and how? MainForm's Show is call just before AppRun, so this wouldn't do... Any help would be much appreciated. Best regards, Normann

Reply by email

Unknown author
to EarMaster - Bent Olsen

Ah, this would seem to explain the reason why the OnDropFiles is never firing in my application.
I have about 15 forms between Application.Initialize; and Application.Run; and I've never mangaed to get it working under Mac OS X, even though I've followed the examples religiously. I also have a "Beta in progresss" form, that appears before the main form is displayed.

Any ideas?

Dominique.

"EarMaster - Bent Olsen" wrote
I might add that this also happens when you call CreateForm for two or

more

Show quoted text 70 lines
forms, where you call ShowModal (as in a user login form) before the first/main form is showing. The ShowModal calls AppProcessMessages, and hence the events disappears before TApplicationProperties on the main form gets these. Best regards, Normann > -----Original Message----- > From: EarMaster - Bent Olsen [mailto:] > Sent: 28. oktober 2009 14:06 > To: ' > Subject: Carbon: Loosing kAEOpenDocuments AppleEvents before AppRun > > Hi, > > I came across a problem when using TApplicationProperties and waiting > for OnDropFiles to be called. > > In a normal Application Initialize, CreateForm, and Run, the > OnDropFiles event is fired, but if something happens in between > Initialize and Run (like multiple CreateForms with a couple of controls > "badly" calling ProcessMessages, or something else causing messages > being released), before AppRun sets up an event handler, the > OnDropFiles event is not fired - likely because the kAEOpenDocuments > message has been released way before. > > You can check this by creating a new application, put a > TApplicationProperties on Form1, assign OnDropFiles to a procedure > which just sets the forms caption to FileNames[0], and in the project > source code: > > ... > Application.Initialize; > Application.CreateForm(TForm1, Form1); > Application.ProcessMessages; > Application.Run; > > You need to create a shortcut to the compiled application on your Mac > Dock, and drag any file on to it - the application should execute, when > it is not running, and give you the name of the file in Form1's > caption. > > The OnDropFiles doesn't fire (that is, if the application wasn't > running and was being executed), but comment out the ProcessMessage and > the OnDropFiles works fine. > > This might be a normal behavior for ProcessMessages to release > unhandled messages, but I wish ProcessMessages could skip if no global > event handler is set, so it is unfortunate TApplicationProperties is > not receiving these messages. > > I'm not using ProcessMessages in the creating process in my > application, but some controls are doing this internally, making it > impossible to get OnDropFiles fired. > > Any tips? I could create the MainForm first, and create the other forms > in an event after Run, but why and how? MainForm's Show is call just > before AppRun, so this wouldn't do... > > Any help would be much appreciated. Best regards, > Normann -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

dmitry boyarintsev
to Unknown author

It seems like AEOpenDocuments event is processed, but since OnDropFiles event is not yet assigned, it's not fired.

So farm I can think of the following solution (in carbon widgetset). AEOpenDocument events and gathered and called on Application.Run, since form events are initialized and would be processed as expected.

thanks,
dmitry

Reply by email

Hans-Peter Diettrich
to dmitry boyarintsev
Show quoted text 6 lines
It seems like AEOpenDocuments event is processed, but since OnDropFiles event is not yet assigned, it's not fired. So farm I can think of the following solution (in carbon widgetset). AEOpenDocument events and gathered and called on Application.Run, since form events are initialized and would be processed as expected.

How are the procedures on other platforms, for this situation? Doesn't Windows convert the dropped files into command line arguments?

If so, similar default processing could be implemented for MacOS - a default OnDropFiles handler, saving the filenames for later use.

DoDi

Reply by email

Unknown author
to dmitry boyarintsev: It seems like AEOpenDocuments event is processed, but since OnDropFiles event is not yet…

So is this now working as expected?

Dominique.

dmitry boyarintsev wrote 9 lines
It seems like AEOpenDocuments event is processed, but since OnDropFiles event is not yet assigned, it's not fired. So farm I can think of the following solution (in carbon widgetset). AEOpenDocument events and gathered and called on Application.Run, since form events are initialized and would be processed as expected. thanks, dmitry

Reply by email

dmitry boyarintsev
to Unknown author
So is this now working as expected?

Yes and no.

It's working as expected from LCL point of view.
It doesn't work as expected from OSX point of view, because AEOpenDocument is used to start an application with opening some file. For other systems command-line parameters are used.

I'm not sure how to fix the problem, yet. So i far i can suggest not to use Application.ProcessMessages in component initialization.

thanks,
dmitry

Reply by email

Hans-Peter Diettrich
to dmitry boyarintsev
Show quoted text 6 lines
It doesn't work as expected from OSX point of view, because AEOpenDocument is used to start an application with opening some file. For other systems command-line parameters are used. I'm not sure how to fix the problem, yet. So i far i can suggest not to use Application.ProcessMessages in component initialization.

When an application *can* be called with command line arguments, IMO a translation into such an argument is the best solution. When an application expects such arguments, it will check and process the passed arguments, regardless of how they have been supplied.

DoDi

Reply by email

Unknown author
to Hans-Peter Diettrich

I'd be in favour of Hans-Peter's solution until something more standard works.

This would at least allow things to work now, even if it is a workaround. As opposed to the current system, which only works in one case.

Remember it is not just the Application.ProcessMessages that is the problem.
It also occurs if you have more than 1 form between .Initialise and .Run

Dominique.

Hans-Peter Diettrich wrote 22 lines
dmitry boyarintsev schrieb: > It doesn't work as expected from OSX point of view, because > AEOpenDocument is used to start an application with opening some file. > For other systems command-line parameters are used. > > I'm not sure how to fix the problem, yet. So i far i can suggest not > to use Application.ProcessMessages in component initialization. When an application *can* be called with command line arguments, IMO a translation into such an argument is the best solution. When an application expects such arguments, it will check and process the passed arguments, regardless of how they have been supplied. DoDi -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

dmitry boyarintsev
to Unknown author
I'd be in favour of Hans-Peter's solution until something more standard works.

Carbon widgetset is not ideal in implementation, but i don't think that brining more "features" to it would make it better. The problem with converting AEOpenDocument to params is that you won't be able to see the difference, between real command params and generated by LCL.
If additional params are always generated and event is fired then application might make double-file openning or the app need some way to know what params are real.

thanks,
dmitry

Reply by email

Hans-Peter Diettrich
to dmitry boyarintsev: Carbon widgetset is not ideal in implementation, but i don't think that brining more…
> I'd be in favour of Hans-Peter's solution until something more standard > works. Carbon widgetset is not ideal in implementation, but i don't think that brining more "features" to it would make it better.

Think about multi-platform applications. Lazarus/RTL/LCL should offer one unique way to deal with dropped files on app start, independent from the target platform. Since it's impossible to distinguish commandline arguments from dropped files on other platforms, special handling is possible only for Carbon, in dedicated Carbon applications.

Show quoted text 6 lines
The problem with converting AEOpenDocument to params is that you won't be able to see the difference, between real command params and generated by LCL. If additional params are always generated and event is fired then application might make double-file openning or the app need some way to know what params are real.

When the event is not handled (Message.Result), the default handler (TApplication.WndProc?) can do whatever seems to be appropriate. On Carbon it can set a flag, in addition to converting the dropped files into commandline arguments. Also Application.Run can try to send the message once more, but this makes things more complicated (when the command line arguments already have been processed by the application...).

A TApplication.OnOpenDocument handler can be introduced, which can be implemented by an application, or a flag can indicate how things should be handled.

DoDi

Reply by email

dmitry boyarintsev
to Hans-Peter Diettrich
Hans-Peter Diettrich wrote
Think about multi-platform applications. Lazarus/RTL/LCL should offer one unique way to deal with dropped files on app start, independent from the target platform.

I can think of Mac OSX only that's able to start application by dragging a document to the application's shortcut (at the dock). AFAIK, Windows (even Win7) doesn't have such ability. So, it's to early to talk about cross-platform behavior.

The bug has been fixed in the revision given in my previous email without additional workarounds. The problem was caused by incomplete event loop initialization.

A TApplication.OnOpenDocument handler can be introduced, which can be implemented by an application, or a flag can indicate how things should be handled.

Yes, that would be a good solution.
Infact, using OnDropFiles is incorrect event for handling "startup open-files" and has been introduced for OSX system compatibility. Dropping files (dragged from Finder) on a form is not yet implemented for Carbon.

thanks,
dmitry

Reply by email

Hans-Peter Diettrich
to dmitry boyarintsev
Show quoted text 5 lines
> Think about multi-platform applications. Lazarus/RTL/LCL should offer one > unique way to deal with dropped files on app start, independent from the > target platform. I can think of Mac OSX only that's able to start application by dragging a document to the application's shortcut (at the dock).

The same for Windows and Linux (at least KDE). Drop files from the Explorer on any application icon on the desktop...

DoDi

Reply by email

EarMaster - Bent Olsen
to dmitry boyarintsev: Everyone interested, please test r22364 dmitry

Hi dmitry,

I made a small simple test app with latest snapshot of Lazarus/FPC, with two forms, one with TApplicationProperties and OnDropFiles, and the second showing as modal before .Run - it seems to work as it should.

Thanks, and best regards,
Normann

Show quoted text 17 lines
-----Original Message----- From: dmitry boyarintsev [mailto:] Sent: 31. oktober 2009 20:10 To: Lazarus mailing list Subject: Re: [Lazarus] Carbon: Loosing kAEOpenDocuments AppleEvents before AppRun Everyone interested, please test r22364 thanks, dmitry -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

dmitry boyarintsev
to EarMaster - Bent Olsen
EarMaster - Bent Olsen wrote
I made a small simple test app with latest snapshot of Lazarus/FPC, with two forms, one with TApplicationProperties and OnDropFiles, and the second showing as modal before .Run - it seems to work as it should.

Normann, could you public the projects?
or create a bug report and attach samples there?

thanks,
dmitry

Reply by email

EarMaster - Bent Normann Olsen
to dmitry boyarintsev

A bug report? Even if it seem to work? :-)

My small test project is very simple - I just create a new empty project, add a new empty form "Form2", beside the default "Form1", and add TApplicationProperties in Form1 and assign OnDropFiles which just sets the forms Caption := FileName[0], and in the project source I add Form2.ShowModal:

begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.CreateForm(TForm2, Form2);
  Form2.ShowModal;
  Application.Run;
end;

When you close Form2, the Form1 should appear and have its caption set to a file name, if you drag a file to the application icon on the Dock - a shortcut to the projects application needs to be on the Dock.

This code did not work before the fix, but it seems fine now.

Best regards,
Normann

Show quoted text 19 lines
-----Original Message----- From: dmitry boyarintsev [mailto:] Sent: 2. november 2009 13:11 To: Lazarus mailing list Subject: Re: [Lazarus] Carbon: Loosing kAEOpenDocuments AppleEvents before AppRun On Mon, Nov 2, 2009 at 3:00 PM, EarMaster - Bent Olsen wrote: > I made a small simple test app with latest snapshot of Lazarus/FPC, with two > forms, one with TApplicationProperties and OnDropFiles, and the second > showing as modal before .Run - it seems to work as it should. Normann, could you public the projects? or create a bug report and attach samples there? thanks, dmitry

Reply by email