MsgBox displays a modal message dialog to the user. Some people like to use them to display debug information because it stops the current method from executing and displays some string that you put there.
For example, let's say you have a TCPSocket on a window. Its events look something like this:
[rbcode]
Sub TCPSocket1.Connected()
MsgBox "Connected"
End Sub
Sub TCPSocket1.DataAvailable()
MsgBox me.ReadAll
End Sub
Sub TCPSocket1.Error()
MsgBox "Error: " + Str( me.LastErrorCode )
End Sub
[/rbcode]
This looks safe enough, right? Wrong! You really should be using System.DebugLog for debug messages. Here's why:
Modal windows (including MsgBox) block the code in the current method or event from executing. However, it does not block other events from firing! This is the expected behavior for all modal windows. So you'll run into a rather goofy situation with the above code if the following happens.
A connection occurs, and the Connected message dialog is shown. While that dialog is shown, some data arrives. Now the DataAvailable dialog is shown at the same time. Already things are weird! Now the connection is terminated by the remote side (for whatever reason), and all of a sudden, the Error dialog pops up as well! If you were expecting all code to stop executing, you'd be in for quite the surprise.
People have reported this as a bug time and again because they'd never run into this before. That was because MsgBox wasn't truly a modal window before 5.5 -- it was a system call that behaved differently on all platforms. So when we made it into a MessageDialog under the hood (and it became modal in the REALbasic sense), people started experiencing this behavior.
I tried "fixing" the issue in the socket code, but it's lead to nothing but heartache. I finally pulled the hacks out because they were causing legit code to fail (such as the EasyTCPSocket class!). People are just going to have to live with the fact that MsgBox is now a modal window (as it should have been in the first place) and behaves the same on all platforms.
Leave a comment