Showing posts with label showmessage. Show all posts
Showing posts with label showmessage. Show all posts

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. 

Thursday, 18 July 2013

How NOT to handle exceptions

Just been working with some code and saw this little gem.

try
  {Some code}
except
  showmessage('error');
end;

This is a good example of the developer being lazy and not being bothered to do something better. Can you imagine the user ringing up support and saying they are getting a 'error' message, it's not even with a capital 'E'. 

There are a couple of issues I have with this bit of code. Firstly I have a rule that showmessage() is used while developing and should be removed when a deployment build is done, if a message needs to be displayed it should be in an message dialog (MessageDlg). The reason for this is that a message dialog looks better with icons specify what the message is, I use GExperts to create the code. Also, when developing I can quickly search for 'showmessage' and can see what messages need to be removed, this means there are no embarrassing debug messages displayed to the user.

Secondly is the message just says error, which it not helpful to the user or the developer when it is reported. The developer could have done something better by giving a more useful message like 'An error has occurred while...', with what the operation is doing. The developer could have also included the exception message like the following.

try
  {Some code}
except 
   on e: exception do
     MessageDlg('An error has occured in...' + e.Message,                mtError, [mbOK], 0);
end;