Changes between Version 3 and Version 4 of Listen
- Timestamp:
- 11/22/11 12:15:13 (13 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Listen
v3 v4 64 64 {{{ 65 65 #!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 72 listen button.clicked, do(sender, args as EventArgs) 73 print 'Quitting' 74 Application.quit 67 75 }}} 68 76 … … 72 80 method invocation.[[BR]] 73 81 In practice this means that most listen statements will have their second 74 argument as a method name prefixed with '''ref'''. 82 argument as a method name prefixed with '''ref'''.[[BR]] 83 You need the '''ref''' keyword to specify a reference to a named method so that it is not invoked. [[BR]] 84 A closure (using '''do''') is itself referring to code (rather than invoking it) so 85 you never need both '''ref''' and '''do''' at the same time.