[Lazarus] Carbon: Loosing kAEOpenDocuments AppleEvents before AppRun

EarMaster - Bent Olsen bent at earmaster.com
Wed Oct 28 15:50:34 CET 2009


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

> -----Original Message-----
> From: EarMaster - Bent Olsen [mailto:bent at earmaster.com]
> Sent: 28. oktober 2009 14:06
> To: 'lazarus at lists.lazarus.freepascal.org'
> 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





More information about the Lazarus mailing list