| 1 | = Ignore = |
| 2 | |
| 3 | Disconnect an event from some particular event handling code by |
| 4 | specifying an existing event handler (method reference) for a particular |
| 5 | Event instance. |
| 6 | |
| 7 | This is the converse of [wiki:Listen]. |
| 8 | |
| 9 | == Grammar == |
| 10 | {{{ |
| 11 | ignore <event>, <method-reference> |
| 12 | }}} |
| 13 | |
| 14 | |
| 15 | == Examples == |
| 16 | {{{ |
| 17 | use System.Windows.Forms |
| 18 | |
| 19 | ... |
| 20 | button = Button(parent=p, autoSize=true, text='One', tag=1) |
| 21 | # connect event and handling code |
| 22 | listen button.click, ref .clickHandler |
| 23 | ... |
| 24 | # disconnect event and its handling code |
| 25 | ignore button.click, ref .clickHandler |
| 26 | ... |
| 27 | def clickHandler(source as Object, args as EventArgs) # doClick |
| 28 | pass |
| 29 | }}} |
| 30 | |
| 31 | Full example showing signature and event declaration and convenience method for firing/raising an event. |
| 32 | {{{ |
| 33 | |
| 34 | # delegate for ActionEvent <eventName>EventHandler |
| 35 | sig ActionEventHandler(sender as Object, args as EventArgs) |
| 36 | |
| 37 | class Generator |
| 38 | # event dcl for event called Action |
| 39 | # event <eventName>Event as <sigName> (<eventName>EventHandler) |
| 40 | event actionEvent as ActionEventHandler |
| 41 | |
| 42 | # (protected) method to raise/fire the event for this class |
| 43 | # {on,fire}<eventName>Event |
| 44 | def _onActionEvent(args as EventArgs) # fireActionEvent |
| 45 | raise .actionEvent, args |
| 46 | |
| 47 | class Listener |
| 48 | # the event handler method do<eventName> |
| 49 | def doAction(source as Object, args as EventArgs) |
| 50 | print 'Event received from [source]' |
| 51 | |
| 52 | ... |
| 53 | def driver |
| 54 | g = Generator() |
| 55 | l = Listener() |
| 56 | |
| 57 | #tie the generator event to the Listener method |
| 58 | listen g.actionEvent, ref l.doAction |
| 59 | |
| 60 | ... |
| 61 | |
| 62 | #untie the event and listener |
| 63 | listen g.actionEvent, ref l.doAction |
| 64 | }}} |
| 65 | |
| 66 | |
| 67 | == Notes == |
| 68 | |
| 69 | The event handler method must be a reference to a method not a |
| 70 | method invocation.[[BR]] |
| 71 | |
| 72 | In practice this means that most ignore statements will have their second |
| 73 | argument as a method name prefixed with '''ref'''. |