delphi 7 - create a custom warning
Asked Answered
B

3

11

I'm using Delphi 7, and I want to create a custom warning message (which will be shown at compile time), 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 they compile/build the sources.

Busywork answered 6/10, 2010 at 10:4 Comment(0)
S
19

In D2007 you can write

{$MESSAGE 'Hello'}

or

{$MESSAGE ERROR 'Hello'}

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

Snapdragon answered 6/10, 2010 at 10:13 Comment(4)
Seems to have been available since Delphi 6.Foah
@Sertac - unfortunately I never noticed that, though our main project is still developed in Delphi 6.Enlarger
Is there some usable approach for Delphi 4?Pendulous
@Pendulous Maybe you can replace {$MESSAGE ERROR Some error message} with something that doesn't compile, maybe simply using some undeclared variable like Some_error_message;. No idea about a warning/hint.Snapdragon
C
5

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'}
Curve answered 6/10, 2010 at 12:24 Comment(0)
E
1

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.

Enlarger answered 6/10, 2010 at 10:46 Comment(3)
You could add something like {$IF dxBuildNumber < 66} {$MESSAGE ERROR 'DX Version >= 66 required} {$IFEND} to a unit.Snapdragon
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.Enlarger
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!Echoism

© 2022 - 2024 — McMap. All rights reserved.