Property is unexpectedly changed when closing a window

Is this supposed to happen?

I have a window that pops up with 4 combo boxes, populated and set to ListIndex = so they display the first item.
When the ‘Done’ button is pressed, this code runs and sets properties inside Module1 (not inside the window):

//SET PROPERTIES BASED ON INDEX POSITION OF COMBO BOXES
TabColumnOne = ComboBox1.ListIndex 
TabColumnTwo = ComboBox2.ListIndex 
TabColumnThree = ComboBox3.ListIndex 
TabColumnFour = ComboBox4.ListIndex

//VALUES BEFORE WINDOW CLOSED
System.DebugLog("TabColumnOne = " + TabColumnOne.ToText)
System.DebugLog("TabColumnTwo = " + TabColumnTwo.ToText)
System.DebugLog("TabColumnThree = " + TabColumnThree.ToText)
System.DebugLog("TabColumnFour = " + TabColumnFour.ToText)

//CLOSE THE WINDOW
WindowmatchColumns.Close

//VALUES AFTER WINDOW CLOSED
System.DebugLog("-------------------")
System.DebugLog("TabColumnOne = " + TabColumnOne.ToText)
System.DebugLog("TabColumnTwo = " + TabColumnTwo.ToText)
System.DebugLog("TabColumnThree = " + TabColumnThree.ToText)
System.DebugLog("TabColumnFour = " + TabColumnFour.ToText)

If I do nothing before pressing the button, the integer property “TabColumnOne” now has a value of -2147483648
If I complete all combo boxes with something other than the first entry, the integer property “TabColumnFour” now has a value of -2147483648

This seems odd. Please can anyone shed any light on this?

EDIT:
link to test file:
dropbox

In general when you have a property that is changing when it shouldn’t do the following: make the property a computed one. Now you have a getter and a setter. For the setter add a break or some logging.

Something is odd with the change event of the combobox. It fires way too often. When you close the window the index of the combobox is changing, too, and resetting your module values.

The values of the properties are correct before closing the window, but after the window closes the property is unexpectedly changed.

I have tracked it down to the closing of the window and am confused as to why this is happening.

When you close the window the controls are also closed & disposed of
Trying to read their values AFTER calling close will give you issues
I’m more surprised you do not get nil object exceptions with this code

The properties are in a separate module to the window.

What version and platform?

Seems correct in 2019r1 on W10, all 0’s

Mac OS X 10.14.4
2019r1
2018r4
2018r3
All the same issue :frowning:

I’ll try and find a windows machine and see if I see the same thing…

Hi Julian,

You’re right, it works just great on windows!
It is very different on Mac OS X… :frowning:
I’ll come up with a workaround.

Interesting. If you break it in PushButton1.Action and debugview the vars are they also out of whack or is it the .ToText that’s causing the issue? Try str(TabColumnOne) instead just out of interest.

You get an extra “Change” event on macOS when you close the window
So the code you have in the combobo xhange event handlers runs and causes the effect youre seeing

Put a boolean on the window “isclosing” and in your button set that to true and then your chnage events can see if that is set and do nothing

Ahh thats the problem

ToText expects an Int64 so there’s a conversion going on with the mac edition, might be worth bugging?

Norman, he’s not reading the vars late…

[quote=434090:@Norman Palardy]You get an extra “Change” event on macOS when you close the window
So the code you have in the combobo xhange event handlers runs and causes the effect youre seeing

Put a boolean on the window “isclosing” and in your button set that to true and then your chnage events can see if that is set and do nothing[/quote]

Hi Norman,

Thank you for the insight; I have removed the change event code (this was doubled up anyway from a previous implementation) and it is now fixed :slight_smile:

Thanks everyone!

Wow, that’s insane! Thanks Norm

ffs … grrrr … damn forum dropped my entire post

  1. add a property to your window
    private isClosing as boolean
  1. in the window open event put
    isClosing = false
  1. add the cancelclose event handler to the window and put in
    isClosing = true
  1. then in the comboboxchange event handler put, as the first 3 lines
     if isClosing then
         return
     end if

Great, thanks Norman, I might put my change event implementation back now!

The actual problem is that you need to use me.ListIndex in the change event, do that and you get the right values for the selections.

HA ! never even looked at the fact he was using “me.index” … :stuck_out_tongue:

They’d be wrong any time you changed any of them even before the close of the Window

Can toss out all my code

Great! I was being an idiot - well kind of.

Sorry for the confusion. It arose because I totally forgot about the code existing in the change event - because I was setting all the properties with the Ok button these change events were redundant. It was the OS X behaviour you pointed out in the first place that triggers change events on window close that was my missing link.

Thanks again, you still solved it!!