Event Assignment Operators

From The Oxygene Language Wiki

Jump to:navigation, search

This is a Language topic
Feel free to add your notes to this topic below.



The event assignment operators (+= and -=) are used to add or remove an event handler from a multicast-delegate type. Events in Delphi Prism don't allow access to the underlying field, they provide a method to Add or Remove a handler from the event instead.

method MyClass.ClickHandler(sender: Object; ea: EventArgs);
begin
end;

method MyClass.AddHandlers;
var
  lButton: System.Windows.Forms.Buton;
begin
  lButton.Click += @ClickHandler; // 1 event handler on the button
  lButton.Click += method begin
    MessageBox.Show('Hello World');
  end; // two event handlers now. 

  lButton.Click -= @ClickHandler; // 1 event handler on the button, the anonymous method above.


See Also


Oxygene-48.png

Area: Oxygene Language
Compiler version: Oxygene 5

Language GlossaryKeywordsTypesFAQHow To

Navigation
Areas
More
Toolbox