Recent

Author Topic: Use of TMainMenu in TFrame  (Read 3301 times)

PatBayford

  • Full Member
  • ***
  • Posts: 125
Use of TMainMenu in TFrame
« on: July 25, 2017, 11:33:59 pm »
Just started a project using TFrames, due to limitations in Form inheritance in Lazarus.
My base Frame includes a TMainMenu, along with several other controls, however, when placed on a TForm, despite the TMainMenu being present, it does NOT function as a menu, (all other controls work fine as far as I can see so far).
I guess this is because the menu's parent is the TFrame, and NOT the TForm? Does anybody have a workaround for this?
Lazarus 1.8.0 FPC 3.0.2 SVN 56594 Windows 10 64bit (i386-win32-win32/win64)

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Use of TMainMenu in TFrame
« Reply #1 on: July 26, 2017, 12:19:27 am »
I believe this is a limitation imposed by the OS which only allows a mainmenu widget to be parented directly by a form (and a frame is not a form, though it is similar to a form).
If this is the case, then the Designer should not allow a TMainMenu to be dropped on a frame. A form with several frames and several "main" menus would be strange and confusing, even if the menus worked.
Since the Designer currently allows you to drop a TMainMenu on a frame, I may be mistaken in my understanding.
Anyway, as you discovered, a mainmenu on a frame does not work. It may not even be shown.

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Use of TMainMenu in TFrame
« Reply #2 on: July 26, 2017, 12:21:10 am »
here try this one out. From a quick test it works it needs work to make it work a bit better but it is a good start.
http://torry.net/vcl/bars/toolbars/menubar.zip
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Use of TMainMenu in TFrame
« Reply #3 on: July 26, 2017, 12:55:00 am »
from a better look it seems it has its quirks and a problem to solve before using it on production code. The quirk is that when the mouse is moved along the bar if a menu is down it will not auto follow your mouse movement, not a bad thing per say but none standard. and the problem is that if a menu is open and you click to open an other menu on the bar it gets confused and shows a very small rectangle instead of the complete menu.
Please keep in mind I did test it with the mainmenu on a frame inside the form and the toolbar on the form.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

wp

  • Hero Member
  • *****
  • Posts: 11922
Re: Use of TMainMenu in TFrame
« Reply #4 on: July 26, 2017, 01:08:54 am »
If you set the MainForm's property Menu to the menu of the frame at runtime (FormCreate event) then the menu shows up and works correctly.

PatBayford

  • Full Member
  • ***
  • Posts: 125
Re: Use of TMainMenu in TFrame
« Reply #5 on: July 26, 2017, 01:34:16 am »
Thanks for the help taaz and wp - wp's solution looks great, but I will try both. I can't remember if this was a problem with Delhi frames, as I did not use them a lot, as form inheritance worked better - the repository was a great idea for re-use of forms!
Lazarus 1.8.0 FPC 3.0.2 SVN 56594 Windows 10 64bit (i386-win32-win32/win64)

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Use of TMainMenu in TFrame
« Reply #6 on: July 26, 2017, 09:48:09 am »
If you set the MainForm's property Menu to the menu of the frame at runtime (FormCreate event) then the menu shows up and works correctly.

This is, of course, all that needs to be done.
And the danger of having two main menus on a single form with several mainmenu-frames is obviated since a form has only one Menu property that can be assigned to, however many frames there might be.

 

TinyPortal © 2005-2018