Author: Yoav Abrahami
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
1 2 {$MESSAGE HINT|WARN|ERROR|FATAL 'text string' }3 4 //and some examples of it (taken from the Delphi help files) are: 5 6 {$MESSAGE 'Boo!'}emits a hint
7 {$MESSAGE Hint 'Feed the cats'}emits a hint
8 {$MESSAGE Warn 'Looks like rain.'}emits a warning
9 {$MESSAGE Error 'Not implemented'}emits an error, continues compiling
10 {$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:
You get a compiler message for each item, reminding you to deal with it.
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):
11 destructor TumbSelectionTempTable.Destroy;
12 begin13 // Clear the temp tables.14 {$MESSAGE Warn ' - remember to free all allocated objects'}15 ClearAllOuterWorldFold;
16 if FSubjectsTempTableCreated then17 DropTempTable(FTableName);
18 19 FOuterWorldsFolded.Free;
20 FQuery.Free;
21 inherited;
22 end;