delphi 编译版本
If you plan on writing Delphi code that should work with several version of the Delphi compiler you need to know under which versions your code gets compiled.
如果计划编写可与多个版本的Delphi编译器一起使用的Delphi代码,则需要知道代码在哪个版本下进行编译。
Suppose you are writing your own commercial custom component. Users of your component might have different Delphi versions than you have. If they try to recompile the component's code—your code—they might be in trouble! What if you were using default parameters in your functions and the user has Delphi 3?
假设您正在编写自己的商业自定义组件 。 您组件的用户可能具有与您不同的Delphi版本。 如果他们尝试重新编译组件的代码(您的代码),则可能会遇到麻烦! 如果您在函数中使用默认参数并且用户拥有Delphi 3,该怎么办?
编译器指令:$ IfDef ( Compiler directive: $IfDef )
Compiler directives are special syntax comments we can use to control the features of the Delphi compiler. The Delphi compiler has three types of directives: switch directives, parameter directives, and conditional directives. Conditional compilation lets us selectively compile parts of a source code depending on which conditions are set.
编译器伪指令是特殊的语法注释,可用于控制Delphi编译器的功能。 Delphi编译器具有三种类型的指令: ■女巫指令,参数指令和条件指令。 条件编译使我们可以根据设置的条件有选择地编译部分源代码。
The $IfDef compiler directive starts a conditional compilation section.
$ IfDef编译器指令将启动条件编译部分。
The syntax looks like:
语法如下:
{$IfDef DefName}
...
{$Else}
...
{$EndIf}
The DefName presents the so-called conditional symbol. Delphi defines several standard conditional symbols. In the "code" above, if the DefName is defined the code above $Else gets compiled.
DefName表示所谓的条件符号。 Delphi定义了几个标准条件符号。 在上面的“代码”中,如果定义了DefName,则将编译$ Else之上的代码。
Delphi版本符号 ( Delphi Version Symbols )
A common use for the $IfDef directive is to test the version of the Delphi compiler. The following list indicates the symbols to check when compiling conditionally for a particular version of the Delphi compiler:
$ IfDef指令的常见用法是测试Delphi编译器的版本。 下表列出了针对特定版本的Delphi编译器进行有条件编译时要检查的符号:
SYMBOL - COMPILER VERSION
符号 -编译器版本
VER80 - Delphi 1
VER80-德尔福1
VER90 - Delphi 2
VER90-德尔福2
VER100 - Delphi 3
VER100-德尔福3
VER120 - Delphi 4
VER120-德尔福4
VER130 - Delphi 5
VER130-德尔福5
VER140 - Delphi 6
VER140-德尔福6
VER150 - Delphi 7
VER150-德尔福7
VER160 - Delphi 8
VER160-德尔福8
VER170 - Delphi 2005
VER170-德尔福2005
VER180 - Delphi 2006
VER180 -Delphi 2006
VER180 - Delphi 2007
VER180 -Delphi 2007
VER185 - Delphi 2007
VER185-德尔福2007
VER200 - Delphi 2009
VER200-德尔福2009
VER210 - Delphi 2010
VER210-德尔福2010
VER220 - Delphi XE
VER220-德尔福XE
VER230 - Delphi XE2
VER230-德尔福XE2
WIN32 - Indicates that the operating environment is the Win32 API.
WIN32-表示操作环境是Win32 API。
LINUX - Indicates that the operating environment is Linux
LINUX-表示操作环境是Linux
MSWINDOWS - Indicates that the operating environment is the MS Windows/li]
MSWINDOWS-表示操作环境是MS Windows / li]
CONSOLE - Indicates that an application is being compiled as a console application
CONSOLE-表示正在将应用程序编译为控制台应用程序
By knowing the above symbols it is possible to write code which works with several versions of Delphi by using compiler directives to compile appropriate source code for each version.
通过了解上述符号,可以通过使用编译器指令为每个版本编译适当的源代码来编写可用于Delphi多个版本的代码。
Note: symbol VER185, for example, is used to indicate Delphi 2007 compiler or an earlier version.
注意:例如,符号VER185用于表示Delphi 2007编译器或更早的版本。
使用“ VER”符号 ( Using "VER" symbols )
It's quite usual (and desirable) for each new Delphi version to add several new RTL routines to the language.
对于每个新的Delphi版本,向该语言添加几个新的RTL例程是很正常的(也是可取的)。
For example, the IncludeTrailingBackslash function, introduced in Delphi 5, adds "\" to the end of a string if it is not already there. In the Delphi MP3 project, I have used this function and several readers have complained that they can't compile the project—they have some Delphi version prior to Delphi 5.
例如,Delphi 5中引入的IncludeTrailingBackslash函数,如果字符串末尾没有“ \”,则将其添加到该字符串的末尾。 在Delphi MP3项目中,我使用了此功能,一些读者抱怨他们无法编译该项目-他们在Delphi 5之前具有一些Delphi版本。
One way to solve this problem is to create your own version of this routine - the AddLastBackSlash function. If the project should be compiled on Delphi 5, the IncludeTrailingBackslash is called. If some of the previous Delphi versions are used, then we simulate the IncludeTrailingBackslash function.
解决此问题的一种方法是创建您自己的例程版本-AddLastBackSlash函数。 如果项目应在Delphi 5上编译,则调用IncludeTrailingBackslash。 如果使用了某些以前的Delphi版本,则我们将模拟IncludeTrailingBackslash函数。
It could look something like:
它可能看起来像:
function AddLastBackSlash(str: string) : string;
begin{$IFDEF VER130}
Result:=IncludeTrailingBackslash(str) ;
{$ELSE}
if Copy(str, Length(str), 1) = "\"
如果复制(STR,长度(STR),1)=
then
“\”,那么
Result := str
else
{$ENDIF}end;
When you call the AddLastBackSlash function Delphi figures out which portion of the function should be used and the other part is simply skipped.
当您调用AddLastBackSlash函数时,Delphi会确定应使用函数的哪一部分,而其他部分将被跳过。
德尔福2008 ( Delphi 2008 )
Delphi 2007 uses VER180 in order to maintain non-breaking compatibility with Delphi 2006 and then adds VER185 in order for development that specifically needs to target Delphi 2007 for whatever reason. Note: any time the interface of a unit changes the code that uses that unit has to be re-compiled.
Delphi 2007使用VER180来保持与Delphi 2006的不间断兼容性,然后添加VER185以便进行开发,无论出于何种原因,该开发都特别需要针对Delphi 2007。 注意:单元的界面更改时,必须重新编译使用该单元的代码。
Delphi 2007 is non-breaking release meaning that DCU files from Delphi 2006 will work as-is.
Delphi 2007是不间断的发行版,这意味着Delphi 2006中的DCU文件将按原样工作。
翻译自: https://www.thoughtco.com/delphi-compiler-version-directives-1058183
delphi 编译版本