Recent

Author Topic: [SOLVED] Strange behavior with TMainMenu  (Read 1848 times)

petevick

  • Sr. Member
  • ****
  • Posts: 419
[SOLVED] Strange behavior with TMainMenu
« on: January 07, 2024, 05:18:13 pm »
In the attachment the Bookmarks submenu has menuitems 1 to 5, these all have a procedure set in their OnCick event. The submenu MenuItem4 also has a procedure set to its OnCick event. When I run the programme, has soon as the '1' menu item is highlighted it's OnClick event is fired, but the menu item was not clicked. If I delete the OnClick from MenuItem4 then item '1' highlights without any action being fired. Is this the expected behavior, or have I missed a property setting somewhere ??
« Last Edit: January 07, 2024, 08:28:00 pm by petevick »
Pete Vickerstaff
Linux Mint 21.2 Cinnamon, Windows 10, Lazarus 3.2, FPC 3.2.2

jamie

  • Hero Member
  • *****
  • Posts: 6891
Re: Strange behavior with TMainMenu
« Reply #1 on: January 07, 2024, 08:16:08 pm »
Long time ago, that bug was discovered because someone put code in the widgets to make it do that, Bad choice, most likely because Delphi does it to a point.

 Then that code was removed and only the menu that actually got clicked on triggered the event, like it should. but then that got deemed as a bug and it was put back to the other bug, which you see now.

 All I can say is, live with it. Test the Sender of the event for child menus and just ignore the event if that is the case.


The only true wisdom is knowing you know nothing

petevick

  • Sr. Member
  • ****
  • Posts: 419
Re: Strange behavior with TMainMenu
« Reply #2 on: January 07, 2024, 08:27:40 pm »
Long time ago, that bug was discovered because someone put code in the widgets to make it do that, Bad choice, most likely because Delphi does it to a point.

 Then that code was removed and only the menu that actually got clicked on triggered the event, like it should. but then that got deemed as a bug and it was put back to the other bug, which you see now.

 All I can say is, live with it. Test the Sender of the event for child menus and just ignore the event if that is the case.
How bizarre. Thanks for the explanation and advice Jamie, I appreciate it  ;D
Pete Vickerstaff
Linux Mint 21.2 Cinnamon, Windows 10, Lazarus 3.2, FPC 3.2.2

Thaddy

  • Hero Member
  • *****
  • Posts: 16945
  • Ceterum censeo Trump esse delendam
Re: [SOLVED] Strange behavior with TMainMenu
« Reply #3 on: January 07, 2024, 08:31:37 pm »
That is a bug in Lazarus since Delphi does not do that. It can also be the case of the widget set, which makes it platform.
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

VisualLab

  • Hero Member
  • *****
  • Posts: 675
Re: [SOLVED] Strange behavior with TMainMenu
« Reply #4 on: January 08, 2024, 04:39:10 pm »
In the attachment the Bookmarks submenu has menuitems 1 to 5, these all have a procedure set in their OnCick event. The submenu MenuItem4 also has a procedure set to its OnCick event. When I run the programme, has soon as the '1' menu item is highlighted it's OnClick event is fired, but the menu item was not clicked. If I delete the OnClick from MenuItem4 then item '1' highlights without any action being fired. Is this the expected behavior, or have I missed a property setting somewhere ??

Do you only use menus (TMainMenu and its nested items), or are these menu items linked to actions collected in the action list (TActionList)?

I'm asking because I've been using the action list for a long time. I create event handlers for actions. And I associate menu items with actions from the action list. I also associate the created actions with toolbars and other GUI elements (many years of experience with Delphi).

petevick

  • Sr. Member
  • ****
  • Posts: 419
Re: [SOLVED] Strange behavior with TMainMenu
« Reply #5 on: January 08, 2024, 05:16:35 pm »
Do you only use menus (TMainMenu and its nested items), or are these menu items linked to actions collected in the action list (TActionList)?

I'm asking because I've been using the action list for a long time. I create event handlers for actions. And I associate menu items with actions from the action list. I also associate the created actions with toolbars and other GUI elements (many years of experience with Delphi).
No the TMainMenu does not use an action list. As it happens my original problem forced me to look at a different solution, which has proved to be far better than my original submenu idea.
I do keep looking at action lists and I suppose one of these days I'll get my head around it. I avoided using the anchor editor for a very long time, then I dipped my toes in, and now I see how extremely useful it is, maybe the same will happen with action lists  ::)
Pete Vickerstaff
Linux Mint 21.2 Cinnamon, Windows 10, Lazarus 3.2, FPC 3.2.2

wp

  • Hero Member
  • *****
  • Posts: 12799
Re: [SOLVED] Strange behavior with TMainMenu
« Reply #6 on: January 08, 2024, 05:38:37 pm »
That is a bug in Lazarus since Delphi does not do that.
No, it does. Run attached Delphi project. For the screenshot (Delphi XE 11.3 CE) which logs the menuitems' OnClick events, I did not click on "Menu 12", the event was fired only by dragging the mouse over the item.

kirchfritz

  • Jr. Member
  • **
  • Posts: 66
  • WIN11 LAZ 2.2.4 FPC 3.2.2
Re: [SOLVED] Strange behavior with TMainMenu
« Reply #7 on: January 08, 2024, 09:04:50 pm »
In the Lazarus IDE's mainmenu every menuitem with a submenu opens automatically the submenu without clicking!
Is this the behaviour, which you dislike?
IMHO this is not a bug. I like automatically opening submenus.

wp

  • Hero Member
  • *****
  • Posts: 12799
Re: [SOLVED] Strange behavior with TMainMenu
« Reply #8 on: January 08, 2024, 09:38:06 pm »
Well, the bug is that the parent of the opening submenu ("Jump to" in your screenshot) fires an OnClick event only by moving the mouse over it, without actually clicking. Normally this does not matter, but users who assign an OnClick handler to the parent item have no way to tell whether a click really occurred.

VisualLab

  • Hero Member
  • *****
  • Posts: 675
Re: [SOLVED] Strange behavior with TMainMenu
« Reply #9 on: January 08, 2024, 10:11:54 pm »
Well, the bug is that the parent of the opening submenu ("Jump to" in your screenshot) fires an OnClick event only by moving the mouse over it, without actually clicking. Normally this does not matter, but users who assign an OnClick handler to the parent item have no way to tell whether a click really occurred.

I just tested it in Delphi (12 Prof.). Since I have been using action lists for many, many years, I forgot about this behavior of the TMainMenu and TMenuItem classes. Perhaps this is due to some strange decision to sparingly implement the above-mentioned classes from the late 1990s in Borland (this is just my guess).

Perhaps, however, the operation of these classes should be improved by adding an event that handles "mouse pointing" at a menu item. But what to call them? Probably not "OnMouseEnter", because then the "OnMouseLeave" event would also have to appear. Maybe something like: "OnMouseOver" or "OnMouseHover" (as in JS)? And most importantly, does WinAPi handle this as a separate event in the system? And how is this handled in KDE and GNOME?

jamie

  • Hero Member
  • *****
  • Posts: 6891
Re: [SOLVED] Strange behavior with TMainMenu
« Reply #10 on: January 08, 2024, 11:21:56 pm »
To add insult to injury, place an auto Checkmark on a parent menu and then mouse over to the child menu back and forth.

The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018