Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Mon Dec 09, 2019 10:13 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 11 posts ] 
Author Message
 Post subject: MsgBox from Inactive Window Hangs App
PostPosted: Tue Dec 13, 2011 9:55 pm 
Offline

Joined: Fri Jul 21, 2006 12:28 am
Posts: 509
I have an application that uses a second window to present a detailed view of data from the main window. The second window doesn't process any data, it calls methods from the main window if the user wants to change something, then its listbox is redrawn to reflect the changes made.

I've recently run into a problem where the app will freeze if a method called from the main window attempts to display a MsgBox while the main window is inactive. I don't have this problem in OS X. I'm not sure if calling a method in one window from another window violates Windows protocols and that is causing the app to hang or if it's the result of a bug in a recent IDE update. Any thoughts on this would be helpful.

_________________
Regards,
Carl
Capaho Web
http://www.capaho.com


Top
 Profile  
Reply with quote  
 Post subject: Re: MsgBox from Inactive Window Hangs App
PostPosted: Wed Dec 14, 2011 4:57 am 
Offline

Joined: Mon Aug 14, 2006 9:33 pm
Posts: 1774
Yes, calling a method in another window can be fraught with danger if not done carefully.
One possibility is to create a new class to handle this data. All methods that act on this data will become methods in this new class. You can instantiate the class in your main window, then pass an instance of the class to your secondary window where the methods will still be available without referring to the main window.

_________________
Roger Clary
Class One Software
Educational Software for Lifelong Learning
http://www.classonesoftware.com


Top
 Profile  
Reply with quote  
 Post subject: Re: MsgBox from Inactive Window Hangs App
PostPosted: Wed Dec 14, 2011 9:20 am 
Offline

Joined: Fri Jul 21, 2006 12:28 am
Posts: 509
The interesting thing about this problem is that it worked before. It's only since I went back to make revisions after 2011r3 that I ran across this bug. The app doesn't freeze when I call a method from another window to the main window unless the main window method tries to draw a MsgBox while the main window is inactive. This is the specific code that seems to be the root of the problem:
Dim i As Integer
i = MsgBox("Do you really want to do that?",36)
If i <> 7 then
// Do that.
Else
// Don't do that.
End if

I think using something else other than a MsgBox might be the simplest workaround.

_________________
Regards,
Carl
Capaho Web
http://www.capaho.com


Top
 Profile  
Reply with quote  
 Post subject: Re: MsgBox from Inactive Window Hangs App
PostPosted: Wed Dec 14, 2011 3:34 pm 
Offline

Joined: Mon Aug 14, 2006 9:33 pm
Posts: 1774
A lot of us, myself included, have gotten away with less than optimal code for years because the compiler or the OS let us do so. One can almost be certain that, at some point, that code is gonna come bite you in the butt. I continue to maintain that one window calling code in another window is not optimal, nor good OOP. The question you need to decide is whether it's worth your time and effort to attempt to get the code right at this point, or whether you need a quick fix and move on.

_________________
Roger Clary
Class One Software
Educational Software for Lifelong Learning
http://www.classonesoftware.com


Top
 Profile  
Reply with quote  
 Post subject: Re: MsgBox from Inactive Window Hangs App
PostPosted: Wed Dec 14, 2011 7:01 pm 
Offline

Joined: Fri Jul 21, 2006 12:28 am
Posts: 509
I don't believe that calling a method in one window from another window is inherently more problematic than using a module. In the case of this app the main window is always open. It appears to me that the problem is specifically with the MsgBox. As far as I can tell, the app hangs because it is waiting for the OK button to be clicked on the MsgBox, but the MsgBox doesn't actually draw if the main window doesn't have focus, so there is no button to click. I'm not sure if this is a Windows issue or an IDE issue, but it's a problem that only recently manifested in an app that's roughly two years old.

_________________
Regards,
Carl
Capaho Web
http://www.capaho.com


Top
 Profile  
Reply with quote  
 Post subject: Re: MsgBox from Inactive Window Hangs App
PostPosted: Wed Dec 14, 2011 9:13 pm 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
I think that where Msgbox is involved, it does make a difference where the code resides, as would any code that uses the concept of "self" to identify a window.

Is the msgbox popping up behind the frontmost window? If you Alt-Tab to the other window or select it from the task bar, do you see the msgbox?

OTOH, I have seen situations on Windows where a Msgbox comes up behind the calling window. It's usually fixed by moving the msgbox out of the event chain via a timer.

Move the msgbox code to a module, it will likely resolve your issue.


Top
 Profile  
Reply with quote  
 Post subject: Re: MsgBox from Inactive Window Hangs App
PostPosted: Wed Dec 14, 2011 9:31 pm 
Offline

Joined: Fri Jul 21, 2006 12:28 am
Posts: 509
timhare wrote:
Move the msgbox code to a module, it will likely resolve your issue.

That's a good idea. I'll give that a try.

_________________
Regards,
Carl
Capaho Web
http://www.capaho.com


Top
 Profile  
Reply with quote  
 Post subject: Re: MsgBox from Inactive Window Hangs App
PostPosted: Thu Dec 15, 2011 1:19 am 
Offline

Joined: Fri Jul 21, 2006 12:28 am
Posts: 509
I tried putting MsgBox in a module but the result was the same. If more than one window is open and the MsgBox isn't called from the active window it doesn't draw but the app waits for its input. Is this a bug in Windows or the IDE or is this normal behavior in Windows? The problem doesn't occur in OS X.

It looks like I will have to use a window with a text area or label for messages in place of the MsgBox for this app to work properly in Windows.

_________________
Regards,
Carl
Capaho Web
http://www.capaho.com


Top
 Profile  
Reply with quote  
 Post subject: Re: MsgBox from Inactive Window Hangs App
PostPosted: Thu Dec 15, 2011 3:17 am 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
What happens if you copy the code into your second window (the active one)? If it still fails, then you've got an event order issue, where the window regains focus after the msgbox is displayed, putting the window in front of the msgbox.


Top
 Profile  
Reply with quote  
 Post subject: Re: MsgBox from Inactive Window Hangs App
PostPosted: Thu Dec 15, 2011 4:52 am 
Offline

Joined: Fri Jul 21, 2006 12:28 am
Posts: 509
timhare wrote:
What happens if you copy the code into your second window (the active one)? If it still fails, then you've got an event order issue, where the window regains focus after the msgbox is displayed, putting the window in front of the msgbox.

The problem appears to be more fundamental. I've moved the windows to the edges of the desktop and there is no MsgBox until I hit alt-tab, when it suddenly appears in the center of the screen. It looks as though the MsgBox isn't drawn until I hit alt-tab rather than it being present but obscured behind another window prior to that.

_________________
Regards,
Carl
Capaho Web
http://www.capaho.com


Top
 Profile  
Reply with quote  
 Post subject: Re: MsgBox from Inactive Window Hangs App
PostPosted: Thu Dec 15, 2011 9:31 pm 
Offline

Joined: Fri Jul 21, 2006 12:28 am
Posts: 509
I replaced MsgBox with MessageDialog in my message module and that solved the problem.

_________________
Regards,
Carl
Capaho Web
http://www.capaho.com


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group