说我们有类似的东西 Private Sub ClickObject(ByVal sender As System.Object, ByVal e as System.Eventargs) Handles Object1.click, Object2.click, Object3.click 在“Handles”之后接受事件并将它们发送到函数. 在Delphi中是
Private Sub ClickObject(ByVal sender As System.Object, ByVal e as System.Eventargs) Handles Object1.click, Object2.click, Object3.click
在“Handles”之后接受事件并将它们发送到函数.
在Delphi中是否有相同的功能,我该怎么做?
是.您可以创建一个事件处理程序并将其分配给多个控件.
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;