Lazarus

Programming => Widgetset => Cocoa => Topic started by: trev on October 22, 2019, 01:45:47 pm

Title: [SOLVED] Help menu duplicated
Post by: trev on October 22, 2019, 01:45:47 pm
When using ShowMessage() or CreateMessageDialog() in any of the FormCreate, FormActivate, or FormShow event handlers, I end up with two Help menus on the Menu bar. The first one has the Search and Help entries, the second one has the Help entry only.

I've worked around it by setting up a TTimer (500ms) to display the message after the main form has been made visible. Is there a better way? I suspect I must be  missing something obvious :)
Title: Re: Help menu duplicated
Post by: howardpc on October 22, 2019, 03:53:08 pm
When using ShowMessage() or CreateMessageDialog() in any of the FormCreate, FormActivate, or FormShow event handlers, I end up with two Help menus on the Menu bar. The first one has the Search and Help entries, the second one has the Help entry only.

I've worked around it by setting up a TTimer (500ms) to display the message after the main form has been made visible. Is there a better way? I suspect I must be  missing something obvious :)
Without seeing compilable code that produces this duplication how can anyone say what might be better?
Title: Re: Help menu duplicated
Post by: trev on October 24, 2019, 05:52:45 am
Any trivial example code will trigger this issue and I thought someone may have come across it before, but fair enough, I've attached a 3Kb zip file of a trivial compilable app with a blank form apart from a TMainMenu control. The unit (as below) has just enough code to provide a working Apple Help Book menu item.

Code: Pascal  [Select]
  1. unit unit1;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5.   Classes, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls,
  6.   Menus, LCLIntf, MacOSAll;
  7. type
  8.   { TForm1 }
  9.   TForm1 = class(TForm)
  10.     MainMenu1: TMainMenu;
  11.     MenuItem_AppHelp: TMenuItem;
  12.     MenuItem_Help: TMenuItem;
  13.     procedure FormShow(Sender: TObject);
  14.     procedure MenuItem_AppHelpClick(Sender: TObject);
  15.   private
  16.   public
  17.   end;
  18. var
  19.   Form1: TForm1;
  20. implementation
  21. {$R *.lfm}
  22. { TForm1 }
  23.  
  24. function GetResourcesPath(): string;
  25. var
  26.   pathRef: CFURLRef;
  27.   pathCFStr: CFStringRef;
  28.   pathStr: shortstring;
  29. begin
  30.   pathRef := CFBundleCopyBundleURL(CFBundleGetMainBundle());
  31.   pathCFStr := CFURLCopyFileSystemPath(pathRef, kCFURLPOSIXPathStyle);
  32.   CFStringGetPascalString(pathCFStr, @pathStr, 255, CFStringGetSystemEncoding());
  33.   CFRelease(pathRef);
  34.   CFRelease(pathCFStr);
  35.   Result := pathStr + '/Contents/Resources/';
  36. end;
  37.  
  38. procedure TForm1.MenuItem_AppHelpClick(Sender: TObject);
  39. var
  40.   helpPath: String;
  41. begin
  42.   helpPath := GetResourcesPath + 'MyApp.help';
  43.   OpenDocument(helpPath );
  44. end;
  45.  
  46. procedure TForm1.FormShow(Sender: TObject);
  47. begin
  48.   ShowMessage('Help Help');
  49. end;
  50.  
  51. end.
  52.  
Title: Re: Help menu duplicated
Post by: howardpc on October 24, 2019, 10:04:08 am
Apologies, I had failed to register that this was a Cocoa-related issue. I am not able to help with that.
Title: Re: Help menu duplicated
Post by: trev on October 24, 2019, 10:44:10 am
No worries - there's an example here now for the next person :)
Title: Re: Help menu duplicated
Post by: VTwin on December 03, 2019, 07:07:22 pm
I ran your app on current fixes and current trunk. In each case the ShowMessage dialog pops up on FormShow. The Help menu is not displayed until the dialog is dismissed. After that the Help menu is displayed with two entries: Search and Help.

Maybe try the fixes branch.
Title: Re: Help menu duplicated
Post by: trev on December 04, 2019, 01:44:01 am
I'll update my trunk and retry.

Curiously, the same behaviour is exhibited under Delphi 10.2.
Title: Re: Help menu duplicated
Post by: VTwin on December 04, 2019, 02:38:30 am
I'll update my trunk and retry.

Curiously, the same behaviour is exhibited under Delphi 10.2.

Have you tried the fixes branch instead of trunk? I only use trunk to test bug fixes, it is generally less stable. No idea about Delphi.
Title: Re: Help menu duplicated
Post by: trev on December 04, 2019, 07:50:19 am
No, I've not tried a fixes branch as Dmitry had fixed various Cocoa blemishes for me which were only in trunk.

As for trunk's stability, I've had excellent luck thus far which is a testament to the committers.

Thanks for your suggestions!
Title: Re: Help menu duplicated
Post by: trev on December 31, 2019, 01:53:23 am
This is now fixed -- it no longer occurs with Lazarus 2.1 r42644 :)
Title: Re: Help menu duplicated
Post by: skalogryz on December 31, 2019, 04:49:20 am
This is now fixed -- it no longer occurs with Lazarus 2.1 r42644 :)
it is also now in fixes branch as well.