Visit our Sponsor   Visit our Sponsor
delphi3000.com - the free delphi knowledge platform
delphi3000.com - the free delphi knowledge platform
Have a look at your member-status

connecting people's knowledge


  - Recent ArticlesRSS feed for Recent Articles on delphi3000.com
  - List of All Articles
  - Top Viewed Articles
  - Articles (+Attachem.)
  - Articles Of Interest
  - Categories
  - Top Uploader
  - Search
  - Index

  - My Home
  - Submit an Article
  - My Articles
  - My Personal Data
  - My Bookmarks
  - Activities
  - Login/Logout

  - Sign Up
  - Why Sign Up
  - Newsletter

  - Press
  - Advertise

  - Contact
  - Feedback





Community
Borland
ClubeDelphi
Dr. Bob
UK-BUG
Delphi Meetings
Planeta Delphi







Startblatt.de






Share this article with friendsShare this article with friends
Rate this articleRate this article - to keep the quality of delphi3000.com !
Comment this article or read through previous comments (7)


What Custom Compiler messages can do for youGo to Yoav Abrahami's websiteFormat this article printer-friendly!Bookmark function is only available for registered users!
Create reminders that generate compiler warnings and errors.
Product:
Delphi 6.x (or higher)
Category:
Object Pascal
Skill Level:
Scoring:
Last Update:
05/12/2002
Search Keys:
delphi delphi3000 article borland vcl code-snippet Object-Pascal Message To-Do
Times Scored:
8
Visits:
3856
Uploader: Yoav Abrahami
Company: TSoft
Reference: N/A
 
Question/Problem/Abstract:
One of the problems of working in a large project is that you need sometimes to mark certain places of you’re source code, remaining you of things you need to do.
We can mark those places in the code, letting Delphi remind us of them.
Answer:



One of the problems of working in a large project is that you need sometimes to mark certain places of you’re source code, remaining you of things you need to do. There are a number of experts for Delphi that provide a to-do list, even one (nice one) that comes with Delphi.

One think that always bugs me about having a separated list of To-Do items is that you have to go and look for it. You can just as well forget all about it, and it loses it’s purpose. Wouldn’t it be nice if we could tell the compiler to generate a message each time a code with To-Do items is compiled?

Another thing is that a To-Do List is good for project level reminders, not a unit of even object level. You need a reference from the To-Do Item to the unit or object, some way of getting from the item to the code.

I find that using custom compiler messages, I can get another way to remind me of what not to forget. It allows me to overcome the two inconveniencies above, letting me insert reminders directly into the code and letting the compiler remind me of them.

The syntax for this command is
{$Message HINT|WARN|ERROR|FATAL 'text string' }
and some examples of it (taken from the Delphi help files) are:
{$Message 'Boo!'}                   emits a hint
{$Message Hint 'Feed the cats'}     emits a hint
{$Message Warn 'Looks like rain.'}  emits a warning
{$Message Error 'Not implemented'}  emits an error, continues compiling
{$Message Fatal 'Bang.  Yer dead.'} emits an error, terminates compiler

One use of this directive that I find very useful is for TBD items – To Be Done. I use it to replace a To-Do list in this case. There are two advantages to this approach:
1. You get a compiler message for each item, reminding you to deal with it.
2. You can browse those messages with the Alt-F8, Alt-F7 keys.

A Code with this directive can look like (just an example from a code I am writing right now):

destructor TumbSelectionTempTable.Destroy;
begin
  // Clear the temp tables.
{$Message Warn ' - remember to free all allocated objects'}
  ClearAllOuterWorldFold;
  If FSubjectsTempTableCreated then
    DropTempTable(FTableName);

  FOuterWorldsFolded.Free;
  FQuery.Free;
  inherited;
end;





Please rate this article!
Skill level:
BeginnerExpert

Useful:
No!Very!

Overall rating:
PoorExcellent



Comments to this article
Write a new comment
Delphi version
    JEan Claude Servaye (May 12 2002 5:38PM)

don't work with Delphi 5 ?

Respond

RE: Delphi version
Jayan Chandrasekhar (May 12 2002 10:47PM)

This works perfectly well in Delphi 6.

I think you left space between  { and $message.

type in
    {$messsage 'it works'}

I found that the above tip is in the delphi help files.  Many a times we do not know that such facilities are available in Delphi.

Thanks for this tip.  It is very useful.
Respond

RE: RE: Delphi version
Jean Claude Servaye (May 12 2002 11:11PM)

Delphi 5 gives this error message:

Invalid compiler directive: 'messsage'
Respond

RE: RE: RE: Delphi version
Yoav Abrahami (May 13 2002 9:49AM)

I tried it on Delphi 5, and it seems that it is not supported.
Vary sad.
Sorry.
Respond

RE: RE: RE: Delphi version
S S B Magesh Puvananthiran (May 15 2002 12:10AM)

Are you sure that you are getting this error message:

Invalid compiler directive: 'messsage'. If so, there is a typo in the word message; you typed as messsage... But I'm not sure whether this will work with Delphi 5 or not...

Good Luck!!!

Thanks.
Magesh.
Respond

RE: RE: RE: RE: Delphi version
giuseppe mazzini (May 22 2002 10:40AM)

I used:

{$Message Warn ' - remember to free all allocated objects'}

but Delphi 5 say: invalid compiler directive: 'message'
Respond

RE: RE: RE: RE: RE: Delphi version
Yoav Abrahami (May 22 2002 2:20PM)

I think that this directive is not supported in Delphi 5.
I don't know of a way to create a work-around for this, but it may be that someone can make one via the Delphi ToolsAPI.
Respond














 
Sign up to consume product discounts for Bronze memberships !

read more


  Visit our Sponsor

 

  Community Ad of
Peganza
 
   














 







     
  Copyright © 2000 - 2007 delphi3000.com - All rights reserved. Terms of use. || Privacy
delphi3000.com is a service by bluestep.com IT-Services GmbH (Vienna)