开发者

calling event within the same Window Form in Delphi Prism

开发者 https://www.devze.com 2023-03-31 16:16 出处:网络
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.

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 err开发者_运维百科ors. 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?


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.


You are not passing the parameters of the method AlarmListBox_Click

Try this

AlarmListBox_Click(nil, nil);
0

精彩评论

暂无评论...
验证码 换一张
取 消