Delegate

Hellow
I worte code this code

d = System::EventHandler.new { |sender,e| puts “1” }

i run code dispay this error
wrong number or type of arguments for `System::EventHandler’
(ArgumentError)

The delegate to inform a direction for use

I don’t think you’d generally want to be initializing an event handler
like that, normally you just want to respond to an event. For
instance, let’s say you have a System::Windows::Forms::Button called
rbutton, you would do something like the following:

rbutton.Click { |sender,e| puts “Clicked!”}

Why do you feel the need to new up an EventHandler directly?

On Feb 3, 2008 12:12 PM, Kim Byung seok [email protected] wrote:


Posted via http://www.ruby-forum.com/.


Ironruby-core mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/ironruby-core


Michael L.
[Polymath Programmer]
http://michaeldotnet.blogspot.com

Michael L. wrote:

rbutton.Click { |sender,e| puts “Clicked!”}

Why do you feel the need to new up an EventHandler directly?

The problem is that this does not providee the ability (as in all other
.NET languages) to do true delegation. In C#, for example, it is
perfectly posssible to delegate the same event handling method to large
numbers of different controls. We have already ‘faked’ delegation in a
similar way to your suggestion (attaching blocks to specific
Control.events) in our current form designer for IronRuby:

http://www.sapphiresteel.com/IronRuby-Visual-Form-Designer
http://www.sapphiresteel.com/IronRuby-Visual-Designer

For a production system, however, this is less than desirable. What we
really need is the normal .NET type of delegate chaining using the +=
and -= operators.

best wishes
Huw

SapphireSteel Software
Ruby and Rails In Visual Studio
http://www.sapphiresteel.com

Michael L. wrote:

I don’t think you’d generally want to be initializing an event handler
like that, normally you just want to respond to an event. For
instance, let’s say you have a System::Windows::Forms::Button called
rbutton, you would do something like the following:

rbutton.Click { |sender,e| puts “Clicked!”}

Why do you feel the need to new up an EventHandler directly?

On Feb 3, 2008 12:12 PM, Kim Byung seok [email protected] wrote:


Posted via http://www.ruby-forum.com/.


Ironruby-core mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/ironruby-core


Michael L.
[Polymath Programmer]
http://michaeldotnet.blogspot.com

^^;

The use is necessary because this code

System::ThreadPool.QueueUserWorItem and
System::Windows::Threading::Dispatcher.BeginInvoke

Above two cords total delegate connection necessary
so i wan’t directly delegate

Yes, it’s half done and will be fixed. All scenarios that are available
in other .NET languages will be doable in Ruby as well.

Tomas

Well, it seems like the event stuff is only half done, let’s say you
add two additional blocks to the Click event. You’ll actually fire
three methods, except it will only be the first one you defined (ie
It’ll say “Clicked!” three times). It seems to have something to do
with the way SetInvocationRule is currently implemented in
RubyEventInfo. I’m sure this’ll be fixed eventually :slight_smile:

What I’m saying is eventually you’ll be able to something like

rbutton.Click{|sender, e| puts “Clicked!”}
rbutton.Click{|sender, e| puts “Also Clicked!”}

and it’ll work like +=ing to two seperate functions.

On Feb 3, 2008 2:48 PM, Huw C. [email protected] wrote:

similar way to your suggestion (attaching blocks to specific
best wishes
[email protected]
http://rubyforge.org/mailman/listinfo/ironruby-core


Michael L.
[Polymath Programmer]
http://michaeldotnet.blogspot.com

You /could/ do:

rbutton.Click {|sender, e| onClick sender}
rbutton2.Click {|sender, e| onClick sender}

Though that’s still not “true” delegation :slight_smile:

On Feb 4, 2008 5:56 AM, Huw C. [email protected] wrote:

do something

Huw


Michael L.
[Polymath Programmer]
http://michaeldotnet.blogspot.com

Michael L. wrote:

What I’m saying is eventually you’ll be able to something like

rbutton.Click{|sender, e| puts “Clicked!”}
rbutton.Click{|sender, e| puts “Also Clicked!”}

That’s still not quite delegation in the usual sense. What if we have:

def onClick( sender )

do something

end

…then have this single method ‘wired up’ to the Click events on, say,
the 50+ buttons of a scientific calculator? In short, the delegated
methods need to be detached from specific objects. I’m sure the IronRuby
team will provide this in time. It makes a big difference when it comes
to implementing code+form integration :wink:

best wishes
Huw

SapphireSteel Software
Ruby and Rails In Visual Studio
http://www.sapphiresteel.com

Does IronRuby work with rspec?

On Mon, 2008-02-04 at 07:28 -0500, Michael L. wrote:

You /could/ do:

rbutton.Click {|sender, e| onClick sender}
rbutton2.Click {|sender, e| onClick sender}

Though that’s still not “true” delegation :slight_smile:

Surely:

on_click_handler = Proc.new {|sender, e| puts “Clicked”}

rbutton.Click &on_click_handler
lbutton.Click &on_click_handler

would do the trick here? Have I missed something? It’s not impossible
to also have:

rbutton.Click -= on_click_handler

later, if you want…


Alex

That’s a bit closer to “true” delegation, in that the same method is
called rather then two seperate methods, but the event handling still
doesn’t work because of the way it generates the AST Rule. Try the
following:

onClick = Proc.new {|sender, e| puts “Called OnClick!” }
onClick2 = Proc.new {sender, e| puts “Called OnClick2!”}

rbutton.Click &onClick
rbutton.Click &onClick2

On Feb 4, 2008 8:47 AM, Alex Y. [email protected] wrote:

Surely:

rbutton.Click{|sender, e| puts “Clicked!”}
the 50+ buttons of a scientific calculator? In short, the delegated
http://www.sapphiresteel.com


Ironruby-core mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/ironruby-core


Michael L.
[Polymath Programmer]
http://michaeldotnet.blogspot.com

On Mon, 2008-02-04 at 10:00 -0500, Michael L. wrote:

Agreed - it’s one step closer, though :slight_smile:


Alex

Wow interesting, is mini_rspec part of IronRuby?

Regards,
Mike

Mike Plavsky:

Wow interesting, is mini_rspec part of IronRuby?

Yes - it ships as part of our tests\specs directory.

Thanks,
-John

Thanks a lot! Tried - works fine!

Regards,
Mike

Mike Plavsky:

Does IronRuby work with rspec?

Not yet. But we do run our specs through mini_rspec, which uses a subset
of rspec features.

-John

Well I figured out how to get events wired up, that was fun :slight_smile:

Personally I’d rather see events wired up like this:

@rbutton.Click.add &Proc
@rbutton.Click.remove &Proc

On Feb 4, 2008 12:40 AM, Tomas M. [email protected]
wrote:

rbutton.Click{|sender, e| puts “Also Clicked!”}

The problem is that this does not providee the ability (as in all other
For a production system, however, this is less than desirable. What we

Michael L.


Michael L.
[Polymath Programmer]
http://michaeldotnet.blogspot.com

Michael L. wrote:

Well I figured out how to get events wired up, that was fun :slight_smile:

Personally I’d rather see events wired up like this:

@rbutton.Click.add &Proc
@rbutton.Click.remove &Proc

The actual syntax is no big deal. To work like other .NET languages and
to provide the same IDE support, however, event handlers need to be
named methods that can be selectively ‘wired up’ either in programming
code or by selecting a method name using Visual Studio’s Events panel. I
have no very strong feelings about the operators ( += and -= or some
alternatives ) but I do think that consistency with existing .NET
delegation standards is important.

best wishes
Huw

SapphireSteel Software
Ruby and Rails In Visual Studio
http://www.sapphiresteel.com

Once we have the method() method, I imagine that will be a little
easier…

I had taken a side trip on implementing that when looking at the
events stuff, but I really wanted to figure out how to get methods
added to events properly, I may take a look at implementing method()
(and methods()) next…

Unless someone tells me to stop.

On Feb 6, 2008 12:48 PM, Huw C. [email protected] wrote:

The actual syntax is no big deal. To work like other .NET languages and

SapphireSteel Software
Ruby and Rails In Visual Studio
http://www.sapphiresteel.com

Posted via http://www.ruby-forum.com/.


Ironruby-core mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/ironruby-core


Michael L.
[Polymath Programmer]
http://michaeldotnet.blogspot.com