John Reed wrote:

> I'm trying to test if a combo box field in FXRuby has changed, to warn
> the user if they hit the Cancel button without saving their changes. 
> Here's the code:
> 
> def cancelentry(sender, sel, ptr)
> 
>     @@stacbo.connect(SEL_CHANGED) do
>      	 if MBOX_CLICKED_NO == FXMessageBox.question(self, MBOX_YES_NO,
>         		"Cancel Update", "Changes made, cancel update?")
>         		handle(nil, MKUINT(ID_CANCEL, SEL_COMMAND), nil)
>        		return 1
> 	end
>     end
> 
> end
> 
> The problem is that the code never displays the message box. What is
> the proper way to code for a SEL_CHANGED event?

The combo box sends a SEL_CHANGED message to its message target 
immediately after the change takes place. For what you're trying to 
accomplish, I think you just want to save the original state of the 
combo box when the dialog box is first initialized:

     def setup(originalValue)
       @originalValue = originalValue
       @stackbo = FXComboBox.new(...)
       @stackbo.setText(originalValue)
     end

and then compare the combo box's current state to this value when they 
click Cancel:

     def cancelentry(sender, sel, ptr)
       if @stackbo.getText() != @originalValue
         if MBOX_CLICKED_NO == FXMessageBox.question(...)
           handle(nil, MKUINT(ID_CANCEL, SEL_COMMAND), nil)
           return 1
         end
       end
     end

You could, alternately, catch the SEL_CHANGED message and set some state 
variable:

     def setup(originalValue)
       @theValueChanged = false
       @stackbo = FXComboBox.new(...)
       @stackbo.connect(SEL_CHANGED) {
         @theValueChanged = true
       }
     end

     def cancelentry(sender, sel, ptr)
       if @theValueChanged
         if MBOX_CLICKED_NO == FXMessageBox.question(...)
           handle(nil, MKUINT(ID_CANCEL, SEL_COMMAND), nil)
           return 1
         end
       end
     end

The problem with this approach (IMO) is that if they change the combo 
box's value from its original value to some new value, then change it 
*back* again before clicking Cancel, it will still show up as a 
"change". So for this kind of situation I prefer to just clone the 
original data the dialog box or form was initialized with, and then 
compare it against the form's current values at the end to decide if 
it's really been changed.

Hope this helps,

Lyle