Recent

Author Topic: Help menu duplicated  (Read 386 times)

trev

  • Full Member
  • ***
  • Posts: 220
  • 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: 3183
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

  • Full Member
  • ***
  • Posts: 220
  • 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: 3183
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

  • Full Member
  • ***
  • Posts: 220
  • 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)