从Microsoft功能区执行命令?

| 由于此线程提供了帮助和建议,因此我使用Microsoft Ribbon Framework创建了我的第一个非Delphi Ribbon。 按照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;
那么,如何将我的TAction分配给功能区? 谢谢。     
已邀请:
        我通过查看提供的示例了解了如何执行命令(不知道我是如何错过它们的!)。这些事件似乎必须独立于TActions进行定义,所以我想这是要走的路。 尽管可以在用于调用功能区命令的过程中链接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;
Ribbon框架内的Samples文件夹将更清楚地演示这一点。可以在以下位置找到该框架:http://www.bilsen.com/windowsribbon/index.shtml     

要回复问题请先登录注册