I have a strange occurrence in my application I’m opening a window that contains DesktopComboBox. If that combo box has focus when the OK button is pressed closing the window with WinRef.Close causes the system to beep. Has anyone seen anything like this.
My application has no System.Beep calls within it and there is no code attached to the Combo box.
Tracing the code through the debugger. The sound is happening when the WinRef.Close method is called. If the combo box does not have focus when the window is hidden there is no beep.
Window1 has the following code in a button:
Var oWindow As winFont = New winFont
' Load Setttings
oWindow.ShowModal( Self )
If oWindow.OK Then
' Save Settings
End If
oWindow.Close ' <------- this is the line that goes beep
winFont uses Hide in the OK and Cancel buttons. Once the details are read by winPreferences it calls Window.Close to tidy up afterwards. The beep doesn’t happen until you dispose of the winFont instance. It only happens when the combo box has focus when the window is hidden. Changing focus before hiding prevents the beep from happening. It feels like something in the core of combobox is generating a beep for some reason.
This is winPreferences, the Grid button opens winFont
The outer window needs to read the settings from the dialog window. The winFont is called from four different places. The window needs to exist after closing so that it can be read from by the caller. Thus the reason it only hides things. The dialog builds an object and the caller reads the object and applies it to the correct parent setting.
In my example it sets the font for a data grid, graph titles, graph labels and graph legend. Putting all that code into the dialog isn’t a good idea in my view.
If you do Self.Close then the window structure is destroyed and you can’t read the result from the dialog.
Will take a look at the menus and implicit instance settings, they are not on purpose.
OK is also a property of the dialog. Self.close would destroy that value.
Just tried adding a menubar to each window. No difference.
Looked at ImpicitInstance and it seems to be on by default for DocumentWindows added to an API2 project. I didn’t set it that way, it seems Xojo did. Changing all window to false still results in a beep.
It would appear the .Close does leave the properties available but the controls are not. I agree that the calling function should not be accessing the controls but is is possible to write code that does.
Attempting to access the controls after .Close causes a NilObjectException. Using .Hide allows both methods to work.
Function ShowModalAndReturnResults as MyResultsClass
self.showModal
if OK then
dim x as new MyResultsClass
x.fontName = ...
x.fontSize = ..
return x
else
retun nil ' user canceled
end if
Then, from the parent window, you can just do this:
dim w as new MyDialogWindow
dim x as MyResultsClass = w.ShowModalAndReturnResults()
I find this is a cleaner design as it makes expclit what data is being returned…