4

When I'm calling an OpenDialog from my form on ButtonClick event. The dialog does not shows as modal and is also displays in taskbar (in WindowsXP). I can return to main form and click Open again and again - popping up several dialogs at once..

How do I make an OpenDialog to be modal in Firemonkey? Is it specifically made so that no modal dialogs are allowed due to multi-platform anture of FM?

EDIT: The bug is fixed in Update 3.

Kromster
  • 7,181
  • 7
  • 63
  • 111
  • Just done a lot of experimenting on your behalf, and there appears to be no way to make it Modal. Not only that, but it appears as though it makes a request for the Platform to produce the Open Dialog and display it, which seems to operate on a separate thread. The best I can come up with at this stage is to Hide the form, Execute the Open Dialog, then Show the form afterward. It sucks, but that's one way! – LaKraven Nov 30 '11 at 14:56
  • Alternatively, you can have a transparent Panel overlay the controls of the form (or disable each control), perhaps add a Blur effect to the form, execute the open dialog, then undo those changes after the dialog closes. Neither of these are elegant solutions, though. – LaKraven Nov 30 '11 at 14:58
  • Thank for your response and effort! – Kromster Nov 30 '11 at 16:48
  • I recommend posting your problem on QC! Do that, post the link here... and I'll try to put some focus on it with Embarcadero for you. This is actually a major flaw in my opinion! A Dialog is useless if it's not modal, and this behaviour inexplicably breaks the linear execution model! – LaKraven Nov 30 '11 at 18:03
  • To my regret I don't have QC account yet. – Kromster Nov 30 '11 at 18:36

1 Answers1

3

I think it's a bug. There are a lot of modal type bugs with FireMonkey, and hopefully they will be fixing them soon. Currently, even modal forms aren't modal.

For your problem, I have a workaround for Windows, but you might not like it.

You need to fix the following line in the TPlatformWin.DialogOpenFiles() method in FMX.Platform.Win.

Under with OpenFile do change:

hwndOwner := 0;

To this:

hWndOwner := FmxHandleToHWND(Application.MainForm.Handle);

The function utilizes the Windows GetOpenFileName API call, even though it's deprecated on Vista and above. If a owner handle is passed in, the dialog is modal, otherwise it's not.

You might want to submit this as a bug to qc.embarcadero.com along with the workaround.

Marcus Adams
  • 53,009
  • 9
  • 91
  • 143