views:

166

answers:

3

hi,

I'm using Delphi 7, and I want to create a custom warning message(which will be showed at compilation), so I can warn other programmers on some modifications. I've searched on the internet but i didn't found anything relevant.

Other solutions, are welcomed as well, as long other programmers are warned about things I want, when the compile/build the sources.

Best regards,

+9  A: 

In D2007 you can write

{$MESSAGE 'Hello'}

or

{$MESSAGE ERROR 'Hello'}

- see the documentation. This works since D6 (info courtesy of Sertac Akyuz).

Ulrich Gerhardt
+1 - This feature was on my wish list for a long time.
splash
Seems to have been available since [Delphi 6](http://www.blong.com/Seminars/Delphi6.htm#Compiler).
Sertac Akyuz
@Sertac - unfortunately I never noticed that, though our main project is still developed in Delphi 6.
splash
After 12 years of Delphi, I learn something new!
Gerry
+1  A: 

Sometimes I also wish that such a feature exists. Unfortunately I don't know any solution that could handle my requirements.

The best approach I could imagine spontaneously would be a separate message file which will be synchronized by an IDE Expert. You can add a new message to this file with this expert like this

new DevExpress components (Build 123) required

and commit it to the VCS repository. After the other developers update their local working copies, the IDE Experts compares and synchronizes the message file with a local copy and displays the new messages.

splash
You could add something like {$IF dxBuildNumber < 66} {$MESSAGE ERROR 'DX Version >= 66 required} {$IFEND} to a unit.
Ulrich Gerhardt
Thank you again @Ulrich! That's a good hint! I wasn't aware of the existence of `$IF`. There was only `$IFDEF` in my mind.
splash
I often see third-party code that could use $IF using lots of $IFDEF, as they want to support older versions of Delphi. As a result people reading the code think it is the only way!
Gerry
+2  A: 

We use $MESSAGE too, but with the WARN directive. Typically to alert developers to not implicitly compile units directly into their exe/bpl if it's already contained in another BPL that they should use as a package. D2005 here.

{$MESSAGE WARN 'File: FOOUNIT contained in PACKAGE:-> FOOLIB'}
Chris Thornton