/EventDispatcher

Dispatch internal notifications

Primary LanguageXojoThe UnlicenseUnlicense

EventDispatcher

A notification dispatch mechanism that enables the broadcast of information to registered observers.

Add a new observer

EventDispatcher.AddObserver observer, notificationName

  • observer is the Xojo object that will receive the notification
  • notificationName is the name of the method that will be run when the notification is received

Example: EventDispatcher.AddObserver Window1, "MyMethod"

Remove an observer

EventDispatcher.RemoveObserver observer, notificationName

  • observer is the Xojo object that will stop receiving the notification
  • notificationName is the name of the notification that you are no longer listening for

Example:
EventDispatcher.RemoveObserver Window1, "MyMethod"

Post a notification

EventDispatcher.Notify sender, notificationName
EventDispatcher.Notify sender, notificationName, userInfo

  • sender is the Xojo object sending the notification, set to Nil if not needed or sending from a module
  • notificationName is the name of the notification that is being broadcast
  • userInfo is a list of optional parameters to be sent with the broadcast

Example:
EventDispatcher.Notify Window1, "MyMethod" // no userInfo parameters being sent EventDispatcher.Notify Window1, "MyMethod2", "hello", "world" // two parameters being sent

Note

The first parameter of the callback method will be the sender, followed by any additional parameters