Forum: FXRuby FXDataTarget: am I doing this fine?‏

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
5b972395a92333843018b4add8af0437?d=identicon&s=25 Damián M. González (igorjorobus)
on 2012-12-27 13:07
Hi guys. Have a question to do, been trying to use FXDataTarget to
handle a group of #FXLabel showing information. Imagine a group of
buttons, each one represents one day in the current month, so will be
around 30 of them. When the user press a button, the groups of labels
will show information, different depending of which button was pressed
last. So the first solution that I though is: "okay... let's make use of
FXDataTarget... for the first time". I did something like this:

@data_target =

@buttons = {}

31.times do │time│
 @buttons[time] =, time.to_s, \
  target: @data_target, selector: FXDataTarget::ID_OPTION.+(time))

@data_target.connect(SEL_COMMAND) do │sender, selector, data│

 This doesn't work, in the label appear a nil value, I also printed it
in the console, and of course it prints nil. Am I doing something wrong?
I expected to the label text change to "1" 'till "31", but doesn't.
Thanks for your time.
5b972395a92333843018b4add8af0437?d=identicon&s=25 Damián M. González (igorjorobus)
on 2012-12-28 13:49
The thread go on..

> Ok, I'm not 100% up on Ruby binding particulars, but some
> 1) FXDataTarget should be connected to a variable (not a value) that will >will
> go out of scope sooner that FXDataTarget itself does. The reason is
> keeps a pointer to this variable, so it can modify or read its value.
> 2) A SEL_COMMAND (or in some cases, a SEL_CHANGED) from a widget can change the
> value of the connected variable (if there is one).
> This works in either of two ways:
> a) an ID_VALUE message is received from the widget; the FXDataTarget will
> depending on the type of the connected variable.
> b) an ID_OPTION + i message is received from the widget. In this case, >the
> value is expected to be an integer type, and is plucked from the message
> itself by subtracting the ID_OPTION. So the value is i in this case.
> 3) A SEL_UPDATE from a widget causes the widget's value to be updated >through
> the datatarget, from the value of its connected variable:
> a) if the message is ID_VALUE, a message is sent to the widget; the
> message id depends on the type of variable connected to the datatarget:
> ID_SETINTVALUE is sent for small integer variables, ID_SETLONGVALUE is
> sent for long integers, ID_SETREALVALUE is sent for floating point
> variables, and ID_SETSTRINGVALUE is sent for string variables.
> b) if the message is ID_OPTION + i, the variable connected to the data-
> target is compared to i, and the widget is sent ID_CHECK or ID_UNCHECK
> if the value is equal or unequal to i.
> Hope this helps,
> -- JVZ
> +------------------------------------------------------------------------>----+
> | Copyright (C) 11:40 12/27/2012 Jeroen van der Zijp. All Rights >Reserved. |
> +------------------------------------------------------------------------>----+

 Okay, the explanation is very clean. I don't know how to interpret the
point 3, since that is not easy to see how it works, because this

 @datatarget =
 @textwidget =, 10, target: @datatarget,
selector: FXDataTarget::ID_VALUE)

 #so if I do


 #it is supposed that the @textwidget will be filled with "Hello" right?
 #because of the selector established, right? the ID_VALUE. It happens.
 #so what happen if I change the selector to an ID_OPTION


 #what happen now?

 @datatarget.value=("Hi there")

 #nothing happens
 #I've tried with another widget

 @checkbutton =, nil, target: @datatarget,
selector: FXDataTarget::ID_VALUE)

 #nothing happens


 #it becomes checked!!
 #if I change the selector to an ID_OPTION the widget will only activate
 #when it receives the number asigned to it in his 'selector'


 #nothing happens, but..


 #the widget becomes checked, interesting right? Is not a simple
behaviour, but now I have it more clear

 So, what I wanted to acomplish was not right with FXDataTargets, I just
found another solution: I give each button a different selector:
FXWindow::ID_LAST.+(1), and go on...
 Then I didn't establish any target for them, so the message is catched
by them own. So to each button I did something like this:

@a_button.connect(SEL_COMMAND) do │sender, selector, data│

 So in that way I can identify which button was pressed an do some
action related.
 I'm very thankfull for the explanation, see you around!! :)
This topic is locked and can not be replied to.