Delphi 中的 VB [(Function) 句柄 ...] 等效项

发布于 2024-10-31 12:55:10 字数 244 浏览 1 评论 0原文

假设我们有类似的东西

Private Sub ClickObject(ByVal sender As System.Object, ByVal e as System.Eventargs) 
Handles Object1.click, Object2.click, Object3.click

,它在“句柄”之后获取事件并将它们发送到函数。

Delphi 中有类似的东西吗?我该怎么做?

Say we had something like

Private Sub ClickObject(ByVal sender As System.Object, ByVal e as System.Eventargs) 
Handles Object1.click, Object2.click, Object3.click

Which takes the event after the 'Handles' and sends them to the function.

Is there an equivalent for this in Delphi, and how would I do it?

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

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

发布评论

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

评论(2

半城柳色半声笛 2024-11-07 12:55:10

TActionList 添加到您的表单中。向其中添加 TAction 并像处理其他控件的 OnClick 事件一样处理其 OnExecute 事件。指定控件的 Action 属性以引用您添加到操作列表中的操作。 (这也会导致控件从关联的操作中获取其标题以及启用和可见属性。这意味着当菜单和工具栏按钮表示相同的命令时,可以更轻松地使它们具有统一的状态。)

Add a TActionList to your form. Add a TAction to it and handle its OnExecute event as you would the OnClick event of some other control. Assign the Action properties of the controls to refer to the action you added to the action list. (This also causes the controls to acquire their captions and enabled and visible properties from the associated action. It's meant to make it easier to have menus and toolbar buttons have uniform states when they represent the same command.)

穿透光 2024-11-07 12:55:10

是的。

您可以创建一个事件处理程序并将其分配给多个控件。

procedure TForm1.ThreeControlsClick(Sender: TObject);
begin
  if Sender = Button1 then
    HandleButton1Click
  else if Sender = ComboBox1 then
    HandleComboBox1Click
  else if Sender = Edit1 then
    HandleEdit1Click;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Button1.OnClick := ThreeControlClick;
  ComboBox1.OnClick := ThreeControlClick;
  Edit1.OnClick := ThreeControlClick;
end;

Yes.

You can create an event handler and assign it to multiple controls.

procedure TForm1.ThreeControlsClick(Sender: TObject);
begin
  if Sender = Button1 then
    HandleButton1Click
  else if Sender = ComboBox1 then
    HandleComboBox1Click
  else if Sender = Edit1 then
    HandleEdit1Click;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Button1.OnClick := ThreeControlClick;
  ComboBox1.OnClick := ThreeControlClick;
  Edit1.OnClick := ThreeControlClick;
end;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文