在Delphi Prism中的同一窗口窗体内调用事件

发布于 2024-12-02 13:27:30 字数 610 浏览 0 评论 0原文

我试图从同一窗口窗体文件的另一个方法中调用单击事件。对我来说这行不通。

例如:

  theClass = partial class(System.Windows.Forms.Form)
    method AlarmListBox_Click(sender: System.Object; e: System.EventArgs);  
  private
  protected
  public
    method DoSomething;
  end;

  method theClass.DoSomething;
  begin
    self.AlarmListBox_Click; <<<this is where i want to call the click event
  end;

无论我做什么,它都会不断引发编译器错误。我尝试了 AlarmListBox.Click、AlarmListBox.performClick 等。

我得到的一些错误:

  1. 没有重载方法“AlarmListBox_Click”,值为 0 参数。
  2. 无法访问底层事件字段

那么,如何在同一窗口窗体内触发事件呢?

I am trying to call a click event from within another a method from the same Window Form file. It just won't work form me.

For instance:

  theClass = partial class(System.Windows.Forms.Form)
    method AlarmListBox_Click(sender: System.Object; e: System.EventArgs);  
  private
  protected
  public
    method DoSomething;
  end;

  method theClass.DoSomething;
  begin
    self.AlarmListBox_Click; <<<this is where i want to call the click event
  end;

No matter what I do, it keeps raising compiler errors. I tried AlarmListBox.Click, AlarmListBox.performClick, etc.

Some of the errors I got:

  1. There is no overloaded method "AlarmListBox_Click" with 0
    parameters.
  2. Cannot access underlying event field

So, how do you fire an event within the same window Form?

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

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

发布评论

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

评论(2

謸气贵蔟 2024-12-09 13:27:30

最好使用默认参数调用事件处理程序:

AlarmListBox_Click(self, EventArgs.Empty);

通过将 self 传递到您定义的方法中,调用源不是 AlarmListBox 而是您的表单。您还可以传入自定义 EventArgs,表明该事件不是由于单击 AlarmListBox 而引发的,而是来自您的代码。

It's best to call the Event handler with the default parameters:

AlarmListBox_Click(self, EventArgs.Empty);

By passing self into the method you define that the source of the call was not the AlarmListBox but your form. You could also can pass in custom EventArgs that state that the Event was not raised because of a click on the AlarmListBox but from your code.

锦爱 2024-12-09 13:27:30

您没有传递方法 AlarmListBox_Click 的参数

试试这个

AlarmListBox_Click(nil, nil);

You are not passing the parameters of the method AlarmListBox_Click

Try this

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