使用TActions而不使用它们的OnExecute事件。

huangapple go评论82阅读模式
英文:

Use TActions without their OnExecute event

问题

我想使用TActions来集中应用程序的主要选项,但不是定义单独的OnExecute事件来运行每个选项,我在考虑在通用的TActionList.OnExecute上使用类工厂,以便通用事件将为每个用户选项创建和运行单独的类。

问题是Delphi会禁用没有OnExecute事件的Actions的菜单选项。所以我的问题是是否可能禁用这种行为,以便菜单选项保持活动状态,即使它们的Action没有任何OnExecute事件,让TActionList.OnExecute或类似的方式以通用方式捕获和处理该选择(通过类工厂)。

如果不行,那么我将直接在MainMenu项上应用相同的机制,但我更愿意使用TActions,因为它也适用于工具栏等地方。

谢谢。

英文:

I would like to use TActions to centralize the main choices of an application, but instead of defining individual OnExecute events to run each option, I was thinking of using a class factory on the general TActionList.OnExecute, so that general event will create and run the individual classes for each user option.

The problem is that Delphi disables the menu options with Actions without OnExecute events. So my question is if it's possible to disable that behaviour, so the menu options remain active even when their Action doesn't have any OnExecute event, letting the TActionList.OnExecute or similar to catch and treat that choice in a generic way (through a class factory).

If not then I will apply the same mechanism directly over the MainMenu items, but I would prefer to use TActions so it will also serve for ToolBars, etc. ...

Thank you.

答案1

得分: 3

TAction 提供了一个名为 DisableIfNoHandler 的公共属性,默认值为 True。如果你在运行时将其设置为 False,你应该能实现你的目标。

英文:

TAction offers a public property DisableIfNoHandler, which defaults to True. If you set it to False at runtime you should achieve your goal.

huangapple
  • 本文由 发表于 2023年7月17日 20:52:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/76704667.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定