Menu

Events

Will Pittenger

Like with .NET, ASIL events are based on [Delegates]. Declaring your event is simple.

delegate command MyDelegateCommand var int i

event MyDelegateCommand MyCommandEvent

When it's time to subscribe, first declare a matching procedure, here a command, and then use the ++ operator. To unsubscribe, use the -- operator. As you may recall, we use the & operator to obtain a delegate instance from a procedure name.

command MatchingCommand var int i
  ' Have the command do soemething

MyCommandEvent ++ &MatchingCommand ' subscribe
MyCommandEvent -- &MatchingCommand ' unsubscribe

Now lets trigger the event. Events are really arrays of delegates derived from EventType. ASIL adds code to call each delegate in the array. If the array is empty, nothing happens.

MyCommandEvent 3

Please note that with [Delegates], you are declaring a type. With events, you're declaring an instance of the event.


Related

Wiki: Delegates
Wiki: Generics
Wiki: Home
Wiki: Keywords
Wiki: keywords-command
Wiki: keywords-event
Wiki: keywords-operator