将TAction重命名为另一种形式 [英] Renaming TAction for another form

查看:77
本文介绍了将TAction重命名为另一种形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2种表单,我想共享一个 TActionManager 并分配 TAction -s。

I have 2 forms which I'd like to share one single TActionManager and assigned TAction-s.

第一个表单是主表单-它包含 TActionManager TAction

First form is main form - it holds TActionManager, TAction with caption "Action".

Form1的主菜单将此动作和menuitem标题属性设置为动作A。
Form2包含Form1,并且还将动作分配给menuitem,并将标题设置为动作B。

Main menu of Form1 has this action and menuitem caption property set to "Action A". Form2 includes Form1 and also assigns action to menuitem and caption is set to "Action B".

在设计期间,一切看起来都很好-菜单项命名为 Form1和Form2中的动作A和动作B,并分配了相同的动作。在运行时,它也可以正常工作(对两种形式都正确处理了OnExecute)。

During design time everything looks good - menu items are named "Action A" and "Action B" in Form1 and Form2 and same action is assigned. It also works fine during runtime (OnExecute is properly processed for both forms).

但是-在运行时,Form1菜单项的标题为动作A,而Form2菜单项的标题为标题动作就像动作标题一样。

However - during runtime, Form1 menu item has caption "Action A" and Form2 has menu item caption "Action" just like the action caption.

我不正确地包含它们,是否可以在Form2上包含Form1以共享动作并更改标题?

Am I including them incorrectly, is it possible to include Form1 on Form2 to share action and to change caption? Is it a bug in D2010 / CB2010?

示例:


  1. 创建Form1是D2010 / CB2010中的错误吗?和Form2,并同时添加主菜单

  2. 将TActionManager拖放到Form1中并在其中创建Action1。

  3. 在Form1 Action1中分配菜单项,然后进行修改标题(标题现在显示为粗体,表明已更改为默认值)

  4. 在Form2中还分配了菜单项Action1(来自Form1 TActionManager),并且还更改了默认标题。

  5. 在运行时中,Form1更改了标题(与Action1.Caption不同),并且Form2与Action1.Caption拥有相同的标题,尽管标题应该是在步骤4中更改的新值。

  1. Create Form1 and Form2 and add main menu to both
  2. Drop TActionManager to Form1 and create Action1 in it.
  3. Assign menu item in Form1 Action1 and after that modify Caption (caption is shown now as bold indicating change from default value)
  4. Assign menu item in Form2 also Action1 (from Form1 TActionManager) and also change default caption.
  5. During runtime now Form1 has changed caption (different from Action1.Caption), and Form2 has identical caption to Action1.Caption although the caption should be new value as changed in step 4.


推荐答案

我转载了您的问题,确实,这是奇怪的行为。除了一个明显的问题,为什么要更改菜单项的标题,以下应该起作用:

I reproduced your issue and indeed, this is strange behaviour. Besides the obvious question why to change the menu items captions, the following should work:

设置两个菜单项的 Action 属性执行相同的操作。现在,菜单项的标题已链接到操作的标题,并请注意,它们不再存储(它们在对象检查器中不再显示为粗体)。随后,将标题从菜单项更改为独立的值,并注意现在已将其存储,并且菜单项的确在设计时进行了相应更改。

Set both menu item's Action property to the same action. Now the captions of the menu items are linked to that of the action and note that they are not stored any longer (they appear not bold in the object inspector). Subsequently, change the captions from the menu items to independent values, and note that they now are stored and that the menu items indeed change accordingly at designtime.

但是在运行时,第二个菜单项的标题确实再次跟随该动作的标题。在我看来,这应该不会发生。

But at runtime, the caption of the second menuitem indeed follows that of the action again. This should not happen in my opinion.

我没有重现的是无法在运行时更改它。以下工作按预期方式进行(此处为D7):

What I did not reproduce is the inabbility to change it at runtime. The following works as expected (D7 here):

procedure TForm2.FormCreate(Sender: TObject);
begin
  mnuAction1.Caption := 'Action B';
end;

确定要更改菜单项的标题而不是操作的标题吗?

Sure you are changing the caption of the menu items instead of that of the action?

这篇关于将TAction重命名为另一种形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆