Wiki

Changes between Initial Version and Version 1 of Ignore

Show
Ignore:
Timestamp:
05/02/10 13:41:25 (15 years ago)
Author:
hopscc
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Ignore

    v1 v1  
     1= Ignore =  
     2 
     3Disconnect an event from some particular event handling code by 
     4specifying an existing event handler (method reference) for a particular  
     5Event instance. 
     6 
     7This is the converse of [wiki:Listen]. 
     8 
     9== Grammar == 
     10{{{ 
     11ignore <event>, <method-reference> 
     12}}} 
     13 
     14 
     15== Examples == 
     16{{{ 
     17use 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... 
     27def clickHandler(source as Object, args as EventArgs)  # doClick 
     28    pass 
     29}}} 
     30 
     31Full example showing signature and event declaration and convenience method for firing/raising an event. 
     32{{{ 
     33 
     34# delegate for ActionEvent  <eventName>EventHandler 
     35sig ActionEventHandler(sender as Object, args as EventArgs) 
     36 
     37class 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 
     47class 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 
     69The event handler method must be a reference to a method not a  
     70method invocation.[[BR]] 
     71 
     72In practice this means that most ignore statements will have their second 
     73argument as a method name prefixed with '''ref'''.