Wiki

Changes between Version 3 and Version 4 of Listen

Show
Ignore:
Timestamp:
11/22/11 12:15:13 (13 years ago)
Author:
hopscc
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Listen

    v3 v4  
    6464{{{ 
    6565#!cobra 
    66 # Todo example using closure/anonymous method 
     66# The event handler method can also be declared using a closure if that's desirable 
     67                listen g.actionEvent, do(source as Object, args as EventArgs) 
     68                    print 'Event received from [source]' 
     69 
     70# Heres an example wrt GTK# declaring an eventhandler for an Application exit button 
     71# the indented code on the lines following the do( is the closure code 
     72listen button.clicked, do(sender, args as EventArgs) 
     73    print 'Quitting' 
     74    Application.quit 
    6775}}} 
    6876 
     
    7280method invocation.[[BR]] 
    7381In practice this means that most listen statements will have their second 
    74 argument as a method name prefixed with '''ref'''.  
     82argument as a method name prefixed with '''ref'''.[[BR]]  
     83You need the '''ref''' keyword to specify a reference to a named method so that it is not invoked. [[BR]] 
     84A closure (using '''do''') is itself referring to code (rather than invoking it) so 
     85you never need both '''ref''' and '''do''' at the same time.