加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

delphi – 从Microsoft功能区执行命令?

发布时间:2020-12-15 09:13:26 所属栏目:大数据 来源:网络整理
导读:由于 this thread中提供的帮助和建议,我使用Microsoft Ribbon Framework创建了我的第一个非Delphi功能区. 在J.Bouchez在该线程中发布的guide之后,我已经设法编译我的项目并看到Microsoft Ribbon正在运行. 但是,在执行Command时,我似乎无法让Ribbon响应输入.
由于 this thread中提供的帮助和建议,我使用Microsoft Ribbon Framework创建了我的第一个非Delphi功能区.

在J.Bouchez在该线程中发布的guide之后,我已经设法编译我的项目并看到Microsoft Ribbon正在运行.

但是,在执行Command时,我似乎无法让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;

那么,如何将我的TA指定给功能区呢?

谢谢.

解决方法

我发现如何从查看提供的样本执行命令(不知道我是如何错过它们的!).事件似乎必须独立于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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读