Lazarus

Programming => Widgetset => Cocoa => Topic started by: VTwin on April 25, 2019, 12:45:53 am

Title: [Solved] Cocoa ShowModal
Post by: VTwin on April 25, 2019, 12:45:53 am
Cocoa TForm.ShowModal does not work properly. I've been resorting to code like this as a workaround:

Code: Pascal  [Select][+][-]
  1. function RunSelectCRNSeriesDlg(series: TStringArray): string;
  2. begin
  3.   if SelectCRNSeriesDlg = nil then
  4.     SelectCRNSeriesDlg := TSelectCRNSeriesDlg.Create(Application);
  5.   SelectCRNSeriesDlg.SetPrefs(series);
  6.   {$IFDEF LCLCOCOA}
  7.   SelectCRNSeriesDlg.Show;
  8.   while SelectCRNSeriesDlg.Visible do
  9.     Application.ProcessMessages;
  10.   {$ELSE}
  11.   SelectCRNSeriesDlg.ShowModal;
  12.   {$ENDIF}
  13.   result := SelectCRNSeriesDlg.GetPrefs;
  14. end;

I'm afraid it has introduced numerous bugs into my releases where I have not included such code. This is a big problem for me.

Has anyone else run into such problems? If so, have you found a better workaround?
Title: Re: Cocoa ShowModal
Post by: skalogryz on April 25, 2019, 02:17:02 am
Cocoa TForm.ShowModal does not work properly.
what exactly doesn't work properly?
Title: Re: Cocoa ShowModal
Post by: VTwin on April 25, 2019, 02:32:21 am
Cocoa TForm.ShowModal does not work properly.
what exactly doesn't work properly?

Thanks. It does not not close properly, closing hides it but does not return control to the calling form. I'll try to come up with a full example demonstrating the problem. Perhaps (?) it is related to the issue I reported in the IDE, where a modal dialog will not close while debugging.
Title: Re: Cocoa ShowModal
Post by: skalogryz on April 25, 2019, 04:48:24 am
Thanks. It does not not close properly, closing hides it but does not return control to the calling form. I'll try to come up with a full example demonstrating the problem.
I've created a project with 2 forms.
Added "Show modal" on form1, where there method calls Form2.ShowModal;
Added a "special close" button on Form2 that is calling Close() method

Launching the app.
- click show Modal - form2 shows up as expected
- click "special close" - the focus returns to form1
- click show Modal again - form 2 shows up as expected
- clock on X icon (close) the focus returns to form2 as expected

Sidenote: I'm using trunk
Title: Re: Cocoa ShowModal
Post by: VTwin on April 25, 2019, 07:31:31 pm
Many thanks. Perhaps it was a mistake on my part?  :-[

I was calling Hide instead of Close. Calling Close works as expected.

However, calling Hide causes odd behavior, which may be a bug. Form2 disappears, but it seems to not lose focus, and it is not possible to gain focus for Form1.

I am on trunk, however I normally use the 2.0 Fixes branch, which I assume is more likely to be stable. Is it possible to merge Cocoa fixes to that branch?
Title: Re: Cocoa ShowModal
Post by: VTwin on April 25, 2019, 07:46:58 pm
It also works as expected if I assign modal result mrOk instead of explicitly closing Form2.
Title: Re: Cocoa ShowModal
Post by: skalogryz on April 25, 2019, 08:18:50 pm
I was calling Hide instead of Close. Calling Close works as expected.

However, calling Hide causes odd behavior, which may be a bug. Form2 disappears, but it seems to not lose focus, and it is not possible to gain focus for Form1.
Win32 works exactly the same way.
It makes sense, because the modality has not been removed. Thus Form1 should not be even available.
The modality is removed only after closing the modal form.
Title: Re: Cocoa ShowModal
Post by: VTwin on April 25, 2019, 09:00:03 pm
Thanks, that is perfectly sensible. I appreciate your response.

I am checking through my code to make sure I did not make the same mistake elsewhere. I never noticed that behavior before, so perhaps this is the first time I did.
TinyPortal © 2005-2018