Parallel to proxy, clojure-clr adds a gen-delegate.  Example code is
in

http://github.com/richhickey/clojure-clr/blob/master/Clojure/Clojure.Source/clojure/samples/celsius.clj

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


On Feb 24, 1:43 am, adam11235 <adam.k.web...@gmail.com> 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 clojure@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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to