Can I generate a custom compiler error? If so, how?

后端 未结 2 1317
孤街浪徒
孤街浪徒 2021-02-02 09:52

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 ver

相关标签:
2条回答
  • 2021-02-02 10:05

    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 
    

    See: http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/devcommon/compdirsmessagedirective_xml.html

    This works in Delphi 6 and later.

    0 讨论(0)
  • 2021-02-02 10:20

    Checking the Delphi version has become easy since CONDITIONALEXPRESSIONS directive was introduced in Delphi 6:

    program requires2010;
    
    {$APPTYPE CONSOLE}
    
    {$IFDEF CONDITIONALEXPRESSIONS}
       {$IF CompilerVersion >= 21.0} // 21.0 is Delphi 2010
         {$DEFINE DELPHI2010}
       {$IFEND}
    {$ENDIF}
    
    begin
    {$IFNDEF DELPHI2010}
      {$MESSAGE Fatal 'Wrong Delphi Version'}
    {$ENDIF}
      Writeln('Continued');
      Readln;
    end.
    
    0 讨论(0)
提交回复
热议问题