Re: [Fxruby-users] DataTargets, and more about messaging.
Status: Inactive
Brought to you by:
lyle
From: Lyle J. <ly...@kn...> - 2003-06-14 15:16:05
|
Hugh Sasse Staff Elec Eng wrote: > Maybe this will help deepen my understanding. I'm building a front > end to some "database", which is probably too grand a name for it. > So I have a login window. I want to have a button to clear the text > fields. I don't see a clear method for FXTextField, ... 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 = "" > ... but then, I'm using a DataTarget, so that doesn't matter; > the two are intimately connected, right? :-) The code below is where I am now. > Before adding the @username.handle() commands, the fields cleared on button > realease, only to get immediately reset to the non-clear values they > just had. Now I get a problem with > > FXRuby.cpp:781: FXASSERT(type!=SEL_NONE) failed. > FXRuby.cpp:781: FXASSERT(type!=SEL_NONE) failed. > > so this suggests I have really munged the messages. 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 standard Ruby assignment semantics). So that doesn't really have any effect on anything (other than eliminating one of your references to 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. @username.handle(@clear_button, MKUINT(0, SEL_CHANGED), "") 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 = "" } Hope this helps, Lyle |