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.
And I don't know how that works in Clojure-CLR, but you might need proxy...
2010/2/24 adam11235 <adam.k...@gmail.com>:
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clo...@googlegroups.com
> Note that posts from new members are moderated - please be patient with your first post.
> To unsubscribe from this group, send email to
> clojure+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
--
Communication is essential. So we need decent tools when communication
is lacking, when language capability is hard to acquire...
- http://esperanto.net - http://esperanto-jongeren.nl
Linux-user #496644 (http://counter.li.org) - first touch of linux in 2004
2010/2/24 Joop Kiefte <iko...@gmail.com>:
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
For other clojure-clr newbies, the Clojure.Source project has some
samples that are helpful.
Thanks, Adam.
On Feb 25, 7:39 am, soyrochus <iwanvanderkle...@gmail.com> wrote:
> Hi Adam,
>
> You need to use the gen-delegate macro to create delegates,
>
> Seehttp://wiki.github.com/richhickey/clojure-clr/clr-interop
Specifically, for adding an EventHandler:
(.add_Click button
(gen-delegate EventHandler [sender args]
(let [c (Double/Parse (.Text tb)) ]
(.set_Text f-label (str (+ 32 (* 1.8 c)) " Fahrenheit")))))
-David