Delphi XE5教程12:注释和编译器指示字
内容源自Delphi XE5 UPDATE 2官方帮助《Delphi Reference》,本人水平有限,欢迎各位高人修正相关错误!
也欢迎各位加入到Delphi学习资料汉化中来,有兴趣者可QQ:34484690@qq.com
3 Comments and Compiler Directives
3注释和编译器指示字
Comments are ignored by the compiler, except when they function as separators (delimiting adjacent tokens) or compiler directives.
注释将被编译器忽略,除非它们用作分隔符(隔开相邻的token)或编译器指示字。
There are several ways to construct comments:
有以下几种方式创建注释:
{ Text between left and right braces is a comment. }
{ 由一对花括号所包含的文字构成注释 }
(* Text between left-parenthesis-plus-asterisk and an asterisk-plus-right-parenthesis is also a comment *)
(* 由左圆括号加一个星号和
一个星号加右圆括号之间的文字也构成注释 *)
// Text between double-slash and end of line is a comment.
// 由两个斜杠开始直到这一行的结束,这里的文字是注释
Comments that are alike cannot be nested. For instance, (*{}*) will. This latter form is useful for commenting out sections of code that also contain comments.
相同方式的注释不能嵌套。例如,(*{}*)可以。这后一种形式是注释掉的代码部分还包含有用的注释。
Here are some recommendations about how and when to use the three types of comment characters:
以下是有关如何以及何时使用三种类型的注释字符的一些建议:
- Use the double-slash (//) for commenting out temporary changes made during development. You can use the Code Editor's convenient CTRL+/ (slash) mechanism to quickly insert the double-slash comment character while you are working.
使用双斜线(//)注释掉开发过程中做出的临时变化。在您工作期间,您可以使用代码编辑器的快捷键Ctrl +/(斜杠)来快速插入双斜线注释字符。
- Use the parenthesis-star "(*...*)" both for development comments and for commenting out a block of code that contains other comments. This comment character permits multiple lines of source, including other types of comments, to be removed from consideration by the compiler.
使用括号星“(*...*)”既为开发的注释和注释掉的代码块,它包含其他注释。此注释字符允许多行源代码,包括其他类型的注释,从考虑由编译器被删除。
- Use the braces ({}) for in-source documentation that you intend to remain with the code.
使用大括号({})在源文档中注释你打算继续保留的代码。注意: {}不能嵌套。
A comment that contains a dollar sign ($) immediately after the opening { or (* is a compiler directive. For example,
若$ 符紧跟在 { 或 (* 之后,则这里的注释是编译器指示字。例如
{$WARNINGS OFF}
tells the compiler not to generate warning messages.
它告诉编译器不要产生警告信息。