How do I programatically add actions to an Action Manager in Delphi 2010

霸气de小男生 提交于 2019-12-06 05:42:47
Sertac Akyuz

short answer:

You're expecting a TActionClientItem to show up as ActionComponent of an TAction. That won't happen since TActionClientItem does not descend from TComponent.

longer answer:

I believe you're adding your item to a menu bar. It seems to be by design that an TAction linked to a menu item would not support the ActionComponent. The items of a menu bar is of type TActionClientItem. This is a 'collection item', not a 'component'. Hence the menu cannot fill in the ActionComponent parameter with the menu item when calling the Execute method of the action link of the selected item. If this sounds confusing, I guess the below quotes from the VCL source would make it clear:

TBasicActionLink.Execute method:

function Execute(AComponent: TComponent = nil): Boolean; virtual;

The passed component is assigned to FAction.ActionComponent before it is executed.

How it's called from TCustomActionMenuBar.ExecAction:

FSelectedItem.ActionLink.Execute;

For the question in the title, I don't think you're doing anything wrong, apart from setting the Caption and ImageIndex of a TActionClientItem is unnecessary, as it's the TAction's title and image which will be shown.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!