从 Microsoft 功能区执行命令?

发布于 2024-11-15 18:06:06 字数 1055 浏览 8 评论 0原文

感谢 此线程<中提供的帮助和建议,我使用 Microsoft Ribbon 框架创建了我的第一个非 Delphi 功能区/a>.

按照 A.Bouchez 在该线程中发布的 指南,我成功编译了我的项目并查看正在运行的 Microsoft Ribbon。

但是,在执行命令时,我似乎无法让功能区响应输入。

我总是使用 TActionManager 来管理我的事件,因此我所需要做的就是将每个 TAction 从 TActionManager 链接到功能区。按照上面链接的教程,我尝试了以下方法但无济于事:

// actNew is the name of a TAction set in the TActionManager
procedure TfrmMain.actNewExecute(Sender: TObject);
begin
  ShowMessage('execute new event');
end;

procedure TfrmMain.CommandCreated(const Sender: TUIRibbon; const Command: TUICommand);
begin
  inherited;

  case Command.CommandId of
    cmdNew: // cmdNew was defined in the Ribbon Designer
    begin
      // link the ribbon commands to the TActions
      actNew.OnExecute(Command as TUICommandAction); // obviously will not work
    end;
  end;
end;

那么,如何将我的 TActions 分配到功能区?

谢谢。

I have created my first non Delphi Ribbon using the Microsoft Ribbon Framework thanks to the help and advice provided in this thread.

Following the guide that A.Bouchez posted in that thread I have managed to compile my project and see the Microsoft Ribbon in action.

However, I cannot seem to get the Ribbon to respond to input when a Command is executed.

I always use the TActionManager to manage my Events, so all I need is to link each TAction from the TActionManager into the Ribbon. Following the tutorial linked above, I tried the following to no avail:

// actNew is the name of a TAction set in the TActionManager
procedure TfrmMain.actNewExecute(Sender: TObject);
begin
  ShowMessage('execute new event');
end;

procedure TfrmMain.CommandCreated(const Sender: TUIRibbon; const Command: TUICommand);
begin
  inherited;

  case Command.CommandId of
    cmdNew: // cmdNew was defined in the Ribbon Designer
    begin
      // link the ribbon commands to the TActions
      actNew.OnExecute(Command as TUICommandAction); // obviously will not work
    end;
  end;
end;

So, how do I assign my TActions to the Ribbon?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

纵山崖 2024-11-22 18:06:06

我通过查看提供的示例找到了如何执行命令(不知道我是如何错过它们的!)。这些事件似乎必须独立于 TAction 来定义,所以我想这就是正确的方法。

可以将 Actions OnExecute 处理程序链接到用于调用功能区命令的过程中,例如:

private
  CommandNew: TUICommandAction;
  procedure CommandNewExecute(const Args: TUICommandActionEventArgs);

  procedure UpdateRibbonControls;
strict protected
  procedure RibbonLoaded; override;
  procedure CommandCreated(const Sender: TUIRibbon; const Command: TUICommand); override;

implementation

procedure TfrmMain.RibbonLoaded;
begin
  inherited;

  Color:= ColorAdjustLuma(Ribbon.BackgroundColor, -25, False);
  UpdateRibbonControls;
end;

// set command states here
procedure TfrmMain.UpdateRibbonControls;
begin
  if Assigned(CommandNew) then
    CommandNew.Enabled:= True;
end;

// assign the commands
procedure TfrmMain.CommandCreated(const Sender: TUIRibbon; const Command: TUICommand);
begin
  inherited;

  case Command.CommandId of
    cmdNew: // command id defined in the ribbon designer
    begin
      CommandNew:= Command as TUICommandAction;
      CommandNew.OnExecute:= NewExecute;
    end;
  end;
end;

// command events
procedure TfrmMain.NewExecute(const Args: TUICommandActionEventArgs);
begin
  actNew.OnExecute(nil); // < this is calling the event code from a TAction      
end;

功能区框架内的 Samples 文件夹将更清楚地演示这一点。该框架可以在这里找到:http://www.bilsen.com/windowsribbon/index.shtml< /a>

I found out how to execute the commands from viewing the samples provided (dont know how I missed them!). The events seem to have to be defined independent of TActions, so I guess that is the way to go.

It is possible though linking the Actions OnExecute handler inside the procedure that is used for calling commands for the Ribbon, example:

private
  CommandNew: TUICommandAction;
  procedure CommandNewExecute(const Args: TUICommandActionEventArgs);

  procedure UpdateRibbonControls;
strict protected
  procedure RibbonLoaded; override;
  procedure CommandCreated(const Sender: TUIRibbon; const Command: TUICommand); override;

implementation

procedure TfrmMain.RibbonLoaded;
begin
  inherited;

  Color:= ColorAdjustLuma(Ribbon.BackgroundColor, -25, False);
  UpdateRibbonControls;
end;

// set command states here
procedure TfrmMain.UpdateRibbonControls;
begin
  if Assigned(CommandNew) then
    CommandNew.Enabled:= True;
end;

// assign the commands
procedure TfrmMain.CommandCreated(const Sender: TUIRibbon; const Command: TUICommand);
begin
  inherited;

  case Command.CommandId of
    cmdNew: // command id defined in the ribbon designer
    begin
      CommandNew:= Command as TUICommandAction;
      CommandNew.OnExecute:= NewExecute;
    end;
  end;
end;

// command events
procedure TfrmMain.NewExecute(const Args: TUICommandActionEventArgs);
begin
  actNew.OnExecute(nil); // < this is calling the event code from a TAction      
end;

The Samples folder inside the Ribbon Framework will demonstrate this more clearer. The Framework can be found here: http://www.bilsen.com/windowsribbon/index.shtml

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文