Ads 468x60px

Smaller time frame always follow the bigger time frame. It's better wait be patience to enter in position than risk with BIG SL. Having strong trading discipline and taking losses when necessary is a sign of serious trading approach
Subscribe:

Labels

Saturday, August 11, 2012

BETTER WAY TO DISPLAY [ERROR] MESSAGES


IF YOU DISPLAY MORE THAN A FEW [ERROR] MESSAGES IN YOUR APPLICATION, USING A SIMPLE METHOD SUCH AS THE FOLLOWING MAY NOT BE THE BEST APPROACH:

Application.MessageBox(
  'File not found', 'Error', mb_OK );
Above method of displaying errors will make it harder to modify actual messages since they are distributed all over your application source code. It may be better to have a "centralized" function that can display error messages, or better yet, a centralized function that can display replaceable error messages. Consider the following example:
type
  cnMessageIDs =
    (
      nMsgID_NoError,
      nMsgID_FileNotFound,
      nMsgID_OutOfMemory,
      nMsgID_ExitProgram
      // list your other error
      // IDs here...
    );

const
  csMessages_ShortVersion
    : array [ Low( cnMessageIDs )..
              High( cnMessageIDs ) ]
      of PChar =
    (
      'No error',
      'File not found',
      'Out of memory',
      'Exit program?'
      // other error messages...
    );

  csMessages_DetailedVersion
    : array [ Low( cnMessageIDs )..
              High( cnMessageIDs ) ]
      of PChar =
    (
      'No error; please ignore!',

      'File c:\config.sys not found.'+
      'Contact your sys. admin.',

      'Out of memory. You need '+
      'at least 4M for this function',

      'Exit program? '+
      'Save your data first!'
      // other error messages...
    );


procedure MsgDisplay(
  cnMessageID : cnMessageIDs );
begin
  // set this to False to display
  // short version of the messages
  if( True )then
    Application.MessageBox(
      csMessages_DetailedVersion[
        cnMessageID ],
      'Error',
      mb_OK )
  else
    Application.MessageBox(
      csMessages_ShortVersion[
        cnMessageID ],
      'Error',
      mb_OK );
end;
Now, whenever you want to display an error message, you can call the MsgDisplay() function with the message ID rather than typing the message itself:
MsgDisplay( nMsgID_FileNotFound );
MsgDisplay() function will not only let you keep all your error messages in one place -- inside one unit for example, but it will also let you keep different sets of error messages -- novice/expert, debug/release, and even different sets for different languages.

comments