可以生成自定义编译器错误吗?如果是这样,怎么办? [英] Can I generate a custom compiler error? If so, how?
问题描述
这是我想要做的我有一个项目必须在某些版本的Delphi或更高版本中编译。我想使用条件编译器指令来测试Delphi版本,然后使用自定义消息生成自定义编译器错误。能够生成一个自定义的编译器警告或提示也将被抛弃,如果一个错误是不可能的。
当然,我可以在条件代码中放一些不可编译的giberish段,没关系但是我的问题是有条件地生成定制编译器错误吗?
谢谢Johan和Serg。 / p>
这是解决方案,更多关于这个问题的细节。我有一个最初在Delphi 2007中构建的应用程序。它包含要连接到Web服务的Internet Direct组件。这些使用SSL。我最近将我的SSL库升级到更高版本,而这些版本并不能很好地与Delphi 2007 Indy组件一起使用。我现在添加了以下编译器指令,以确保不再使用Delphi 2007或更早版本编译此应用程序:
{$ IF CompilerVersion< = 19.0} // Delphi 2007 = 19.0
{$ MESSAGE Error'此项目必须在Delphi 2009或更高版本中编译}
{$ IFEND}
您可以使用:
{$ Message HINT | WARN | ERROR | FATAL'text string'}
{$ MESSAGE'Boo!'}发出提示
{$消息提示'喂猫'}发出提示
{$ messaGe警告'看起来像下雨'}发出警告
{$消息错误'未实现'}发出错误,继续编译
{$ Message Fatal'Bang。 Yer死了'}发出错误,终止编译器
这在Delphi 6及更高版本中有效。
Here is what I want to do. I have a project that must be compiled in some version of Delphi or later. I would like to use a conditional compiler directive to test the Delphi version, and then cause a custom compiler error to be generated with a custom message. Being able to generate a custom compiler warning or hint would also be adaquate if an error is not possible.
Sure, I could put some un-compilable giberish in the conditional code segment, and that's fine. But my question is "Can I generate, conditionally, a custom compiler error?"
Thank you Johan and Serg.
Here is the solution, and more details about the issue. I have an application that was originally built in Delphi 2007. It includes Internet Direct components to attach to a Web service. These use SSL. I recently upgraded my SSL libraries to a later version, and these don't play so well with the Delphi 2007 Indy components. I have now added the following compiler directives to ensure that this application will no longer be compiled with Delphi 2007 or earlier:
{$IF CompilerVersion <= 19.0} // Delphi 2007 = 19.0
{$MESSAGE Error 'This project must be compiled in Delphi 2009 or later'}
{$IFEND}
You can use:
{$Message HINT|WARN|ERROR|FATAL 'text string' }
{$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
This works in Delphi 6 and later.
这篇关于可以生成自定义编译器错误吗?如果是这样,怎么办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!