Re: [Fxruby-users] DataTargets, and more about messaging.
Status: Inactive
Brought to you by:
lyle
From: Hugh S. S. E. E. <hg...@dm...> - 2003-06-16 09:11:07
|
On Sat, 14 Jun 2003, Lyle Johnson wrote: > If memory serves, Jeroen has added a clear() method for FXTextField in > FOX 1.2, but you're correct that it's not there for FOX 1.0. You would > just need to set the text field's text to the empty string, i.e. > > aTextField.text = "" OK, that makes sense... > > OK, so focusing on the SEL_COMMAND handler block for @clear_button, I > can see a few things that are definitely wrong. Back at the top of the > LoginWindow#initialize method, you set @user as follows: > > @user = FXDataTarget.new("") > > and so @user holds a reference to a FXDataTarget instance. So far, so > good. But the first line of the SEL_COMMAND handler for @clear_button is: > > @user = "" > > which constructs a new String, and assigns it to @user (this is just DOH! Good point, I was forgetting this fundamental aspect of ruby! <blush/> [...] > that data target object). The next line: > > @username.text = "" > > is a good guess, and I wish it would have worked (but I know why it > doesn't). I'll come back to that in a moment. The next line: > > @username.handle(@clear_button, SEL_CHANGED, "") > > is also a good guess, but more complicated than you would want. If you > did want to take this route, though, you'd need to fix the second > argument to handle() so that it includes both the message type and > message identifier, e.g. Yes, I thought that was probably part of it, since the last correpsondence... > > @username.handle(@clear_button, MKUINT(0, SEL_CHANGED), "") Yes, I've seen things like this in the C++, but this reads to me like "make an unsigned Int of (0,SEL_CHANGED)" so the "magic" must lie in that first parameter? Would you have a ref to point me at for this, please? I may not need the details now given the info below, but it would be good to understand. > > But again, this looks ugly, and there's a better way. > > When you've attached a data target to one or more widgets and want to > update the value of that data target programmatically (e.g. resetting > the string to the empty string), you want to use the FXDataTarget#value > accessor methods. So for your case, you should be able to write the > SEL_COMMAND handler for @clear_button as follows: > > @clear_button.connect(SEL_COMMAND) { > @user.value = "" > @pass.value = "" > } That is a lot nicer. Thank you. And hence this is not .text because it is not the GUI element that is being changed. > > Hope this helps, > > Lyle > > Thank you, Hugh |