Recent

Author Topic: Help menu duplicated  (Read 1102 times)

trev

  • Sr. Member
  • ****
  • Posts: 254
  • Former Delphi 7 and Delphi 10.2 User
Help menu duplicated
« 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 :)
o Lazarus v2.1.0 r61775, FPC v3.3.1 r42640, macOS 10.14.6 (with sup update), Xcode 10.3
o Lazarus v2.1.0 r61574, FPC v3.3.1 r42318, FreeBSD 12.0 (Parallels VM)
o Lazarus v2.1.0 r61574, FPC v3.0.4, Ubuntu 18.04 (Parallels VM)

howardpc

  • Hero Member
  • *****
  • Posts: 3201
Re: Help menu duplicated
« Reply #1 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?

trev

  • Sr. Member
  • ****
  • Posts: 254
  • Former Delphi 7 and Delphi 10.2 User
Re: Help menu duplicated
« Reply #2 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.  
o Lazarus v2.1.0 r61775, FPC v3.3.1 r42640, macOS 10.14.6 (with sup update), Xcode 10.3
o Lazarus v2.1.0 r61574, FPC v3.3.1 r42318, FreeBSD 12.0 (Parallels VM)
o Lazarus v2.1.0 r61574, FPC v3.0.4, Ubuntu 18.04 (Parallels VM)

howardpc

  • Hero Member
  • *****
  • Posts: 3201
Re: Help menu duplicated
« Reply #3 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.

trev

  • Sr. Member
  • ****
  • Posts: 254
  • Former Delphi 7 and Delphi 10.2 User
Re: Help menu duplicated
« Reply #4 on: October 24, 2019, 10:44:10 am »
No worries - there's an example here now for the next person :)
o Lazarus v2.1.0 r61775, FPC v3.3.1 r42640, macOS 10.14.6 (with sup update), Xcode 10.3
o Lazarus v2.1.0 r61574, FPC v3.3.1 r42318, FreeBSD 12.0 (Parallels VM)
o Lazarus v2.1.0 r61574, FPC v3.0.4, Ubuntu 18.04 (Parallels VM)

VTwin

  • Hero Member
  • *****
  • Posts: 793
  • Former Turbo Pascal 3 user
Re: Help menu duplicated
« Reply #5 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.
« Last Edit: December 03, 2019, 07:22:27 pm by VTwin »
“Talk is cheap. Show me the code.” -Linus Torvalds

macOS 10.13.6: Lazarus 2.0.7 fixes svn 62300 (64 bit Cocoa)
Ubuntu 18.04.3: Lazarus 2.0.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.0.6 (64 bit on VBox)
fpc 3.0.4

trev

  • Sr. Member
  • ****
  • Posts: 254
  • Former Delphi 7 and Delphi 10.2 User
Re: Help menu duplicated
« Reply #6 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.
o Lazarus v2.1.0 r61775, FPC v3.3.1 r42640, macOS 10.14.6 (with sup update), Xcode 10.3
o Lazarus v2.1.0 r61574, FPC v3.3.1 r42318, FreeBSD 12.0 (Parallels VM)
o Lazarus v2.1.0 r61574, FPC v3.0.4, Ubuntu 18.04 (Parallels VM)

VTwin

  • Hero Member
  • *****
  • Posts: 793
  • Former Turbo Pascal 3 user
Re: Help menu duplicated
« Reply #7 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.
“Talk is cheap. Show me the code.” -Linus Torvalds

macOS 10.13.6: Lazarus 2.0.7 fixes svn 62300 (64 bit Cocoa)
Ubuntu 18.04.3: Lazarus 2.0.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.0.6 (64 bit on VBox)
fpc 3.0.4

trev

  • Sr. Member
  • ****
  • Posts: 254
  • Former Delphi 7 and Delphi 10.2 User
Re: Help menu duplicated
« Reply #8 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!
o Lazarus v2.1.0 r61775, FPC v3.3.1 r42640, macOS 10.14.6 (with sup update), Xcode 10.3
o Lazarus v2.1.0 r61574, FPC v3.3.1 r42318, FreeBSD 12.0 (Parallels VM)
o Lazarus v2.1.0 r61574, FPC v3.0.4, Ubuntu 18.04 (Parallels VM)