如何在运行时分配ToolButton的OnClick事件? [英] How can I assign the OnClick event of a ToolButton at runtime?

查看:159
本文介绍了如何在运行时分配ToolButton的OnClick事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在设计时创建了一个没有ToolButtons的TToolBar。我的想法是在运行时创建ToolButtons,并在创建表单时将它们放在那里,只是为了向用户显示什么样的表单,而不需要在主菜单中打开一个Windows菜单。

I have a TToolBar created in design time with no ToolButtons. My idea is to create ToolButtons in runtime and place them there when my forms are created, just to show the user what forms are opened without needing to open a "Windows" menu in the main menu.

我有一个名为NavigationUtils.pas的单位,用于存储导航的过程/功能(创建表单时创建按钮)。

I have an unit named NavigationUtils.pas that I use to store the procedures / functions about navigation (as the creation of the buttons when my forms are created).

问题是:如何在创建ToolButton时配置OnClick事件?

The question is: How can I configure the OnClick event when the ToolButtons are created?

推荐答案

从评论中很明显,您没有将 TNotifyEvent 分配给 OnClick 事件。 TNotifyEvent 的声明是:

From the comments it is clear that you are not assigning a TNotifyEvent to the OnClick event. The declaration of TNotifyEvent is:

TNotifyEvent = procedure(Sender: TObject) of object;

所以你需要一个过程,单个参数类型为 TObject ,并且该过程必须是对象的方法。所以,这样的东西:

So you need a procedure, with a single parameter of type TObject, and the procedure must be the method of an object. So, something like this:

procedure TMyForm.ToolButtonClick(Sender: TObject);

然后你可以这样分配:

NewToolButton.OnClick := ToolButtonClick;

这篇关于如何在运行时分配ToolButton的OnClick事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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