[fxruby-users] fox/fxruby message and handler
lyle at lylejohnson.name
Tue Feb 17 10:19:41 EST 2009
On Mon, Feb 16, 2009 at 7:20 PM, Andreas S <andreas_s at hotmail.com> wrote:
> I couldn't figure out why my message-handler does not work. My test code is
> at the end of this email.
> Case 1:
> The 'data' argument to the message handler comes out as an integer instead
> of my ruby string "joke". Can't I pass any ruby object?
No, you can't pass any Ruby object; it needs to be the kind of data
that the target object is expecting for the message type and selector.
It appears that you're wanting to change the label's text whenever the
button is pressed, right? In that case, you'd want to do something
label.text = "joke"
> I've seen fxruby doc appendix C, where it is recommended to query the sender instead of
> interpreting the data. Is this the answer, don't pass data when sending
Yes, that's probably the best way for most cases.
> Case 2:
> This connect target is never executed. What did I do wrong?
You're calling connect(SEL_COMMAND) in the Label's initialize()
method, which means you're calling connect(SEL_COMMAND) on the label
itself. If the label widget actually sent a SEL_COMMAND to its target,
the code in this block would get executed, but because the label
doesn't send out any messages, this is basically inoperative code.
> I'm certain I must have misunderstood something here. I'd be happy if you
> can explain or point me to a doc or faq.
If you check the FOX web site:
you'll find some documentation on how targets and messages work. (The
FOX web site seems to be down at the moment, but perhaps it will be
back online by the time you read this.) There is also a good
discussion of these topics in the FXRuby book from the Pragmatic
Hope this helps,
More information about the fxruby-users