Hi Adam, You need to use the gen-delegate macro to create delegates,
See http://wiki.github.com/richhickey/clojure-clr/clr-interop The signature of the macro is (gen-delegate Type [args] body) whereby in case of event-handlers you would typically use the EventHandler class. The code becomes then: (System.Reflection.Assembly/LoadWithPartialName "System.Windows.Forms") (import '(System.Windows.Forms MessageBox Form Button)) (defn windowsPlay [] (let [win (Form.) temp-button (Button.)] (.. win (get_Controls) (Add temp-button)) (doto temp-button (.set_Top 50) (.set_Text "Clicky") (.add_Click (gen-delegate EventHandler [sender args] (MessageBox/ Show "I got clicked")))) (doto win (.set_Text "hello") (.ShowDialog)))) (windowsPlay) Regards, Iwan On Feb 24, 7:43 am, adam11235 <[email protected]> wrote: > Hi, > > I've made progress in creating a simple app to show a windows form, > however I am having trouble wiring up a delegate (to handle button > clicks). > > The Java version uses Proxy to implement ActionListener, instead I am > just trying to create an EventHandler passing as the 2nd constructor > argument the code I would like executed. (see the .add_Click line) > > The delegate code gets invoked immediately instead of when the button > click occurs, and then complains it expected a function pointer rather > than the DialogResult it received (due to execution of the code) > > I tried quoting that code but no success. > > How do you wire up delegates? > > (import '(System.Windows.Forms MessageBox Form Button)) > > (defn windowsPlay [] > (let > [ win (Form.) > temp-button (Button.) > ] > (.. win (get_Controls) (Add temp-button)) > (doto temp-button > (.set_Top 50) > (.set_Text "Clicky") > (.add_Click (EventHandler. temp-button (MessageBox/Show "I got > clicked")))) > (doto win > (.set_Text "hello") > (.ShowDialog)))) > > (windowsPlay) > > Thanks, Adam. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to [email protected] Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/clojure?hl=en
