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

后端 未结 2 1316
孤街浪徒
孤街浪徒 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: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.
    

提交回复
热议问题