Wiki
Version 5 (modified by Charles, 12 years ago)

--

Ignore

Disconnect an event from some particular event handling code by specifying an existing event handler (method reference) for a particular Event instance.

This is the converse of Listen.

Grammar

ignore <event>, <method-reference>

Examples

use System.Windows.Forms

...
        button = Button(parent=p, autoSize=true, text='One', tag=1)
        # connect event and handling code
        listen button.click, ref .clickHandler
        ...
        # disconnect event and its handling code
        ignore button.click, ref .clickHandler
...
def clickHandler(source as Object, args as EventArgs)  # doClick
    pass

Full example showing signature and event declaration and convenience method for firing/raising an event.


# delegate for ActionEvent  <eventName>EventHandler
sig ActionEventHandler(sender as Object, args as EventArgs)

class Generator
    # event dcl for event called Action
    # event <eventName>Event as <sigName> (<eventName>EventHandler)    
    event actionEvent as ActionEventHandler

    # (protected) method to raise/fire the event for this class 
    # {on,fire}<eventName>Event
    def _onActionEvent(args as EventArgs)      # fireActionEvent
        raise .actionEvent, args

class Listener
    # the event handler method do<eventName>
    def doAction(source as Object, args as EventArgs)
        print 'Event received from [source]'

...
    def driver
        g = Generator()
        l = Listener()
        
        #tie the generator event to the Listener method
        listen g.actionEvent, ref l.doAction

        ...    

        #untie the event and listener
        ignore g.actionEvent, ref l.doAction

Notes

The event handler method must be a reference to a method not a method invocation.

In practice this means that most ignore statements will have their second argument as a method name prefixed with ref.

See Also