Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
Better way to display [error] messages Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
15-Jan-03
Category
Dialogs
Language
Delphi 2.x
Views
181
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Lou Adler

Better way to display [error] messages

Answer:

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:
1   
2   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:

3   type
4     cnMessageIDs =
5       (
6       nMsgID_NoError,
7       nMsgID_FileNotFound,
8       nMsgID_OutOfMemory,
9       nMsgID_ExitProgram
10      // list your other error
11      // IDs here...
12      );
13  
14  const
15    csMessages_ShortVersion: array[Low(cnMessageIDs)..High(cnMessageIDs)] of PChar =
16    (
17      'No error',
18      'File not found',
19      'Out of memory',
20      'Exit program?'
21      // other error messages...
22      );
23  
24    csMessages_DetailedVersion: array[Low(cnMessageIDs)..High(cnMessageIDs)]
25    of PChar =
26      (
27      'No error; please ignore!',
28  
29      'File c:\config.sys not found.' +
30      'Contact your sys. admin.',
31  
32      'Out of memory. You need ' +
33      'at least 4M for this function',
34  
35      'Exit program? ' +
36      'Save your data first!'
37      // other error messages...
38      );
39  
40  procedure MsgDisplay(
41    cnMessageID: cnMessageIDs);
42  begin
43    // set this to False to display
44    // short version of the messages
45    if (True) then
46      Application.MessageBox(csMessages_DetailedVersion[cnMessageID], 'Error', mb_OK)
47    else
48      Application.MessageBox(csMessages_ShortVersion[cnMessageID], 'Error', mb_OK);
49  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:
50  
51  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.

			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC