Wednesday 19 April 2017

Only use ShowMessage() function for debugging

I always use the ShowMessage function for debugging while doing development and always exclude it from release code for the following reasons:


  1. MessageDlg or MessageBox functions are much better as a popup dialog than ShowMessage, they have more options and the presentation is better giving the user a visual icon categorising the meaning of the popup.
  2. It is easy to search through all the code and check there is no 'ShowMessage' operational before checking in the code. I had a customer call me once saying they have a popup (ShowMessage) which just says 'Hello', this was because the developer forgot to remove or comment out the ShowMessage before checking in.
  3. Because there is no icon with a ShowMessage, some testers and end users assume the popup is an error dialog. I have had the same but to a lesser extent with MessageDlg, the icon helps to show when it is information, warning or confirmation.
Some developers seem to use ShowMessage to quickly display information to the user, they are using ShowMessage because they think it is quicker to use, but in GExperts there is a Message Dialog tool that creates the code based on the options the developer sets.

There is the argument not to use these popup at all, and in some applications they cause issues. I think that popups can be annoying to the user if used too much, but I do not have a problem with them if they are used sparingly and they do not cause problems with the operation of the application.

I imagine some developers might say you should never use ShowMessage to debug and use breakpoints while debugging, which in most cases is the true, but there are occasions when some testing by the developer might be done in a non-development environment, in which case you cannot use the debugger.