How to use pre-compiling instructions in Delphi

Source: Internet
Author: User
Tags valid

In Delphi, there are also precompiled instructions similar to C, although the instruction is valid only in the current single file (or it may be that the author does not fully understand the true usage of the instruction), this type of instruction does have a pretty good purpose for making multiple versions of the work (e.g., from the standard version of the learning version).

A Instruction Introduction:

1. Define directive:

Format: {$DEFINE name} Description: Used to define a sign (symbol) that is valid in the current cell. Once defined, you can use if Def and ifndef directives to determine if the symbol exists.

2. UNDEF directive: Format: {$UNDEF name} Description: Used to cancel a sign (symbol) that is already defined in the current cell. This instruction is used in conjunction with define.

3. IFDEF directive: Format: {$IFDEF name} Description: If the name after the directive has already been defined, then the code snippet between {$ELSE} or {$ENDIF} is compiled.

4. IFNDEF directive: Format: {$IFNDEF name} Description: If the name after the directive is undefined, then the code snippet between {$ELSE} or {$ENDIF} is compiled after compiling the directive.

5. IFOPT directive: Format: {$IFOPT switch} Description: If the switch after the instruction has been set up, compile the instruction until the code snippet between {$ELSE} or {$ENDIF}. For example: {$IFOPT r+} writeln (' Open range check switch at compile time '); {$ENDIF}

6. ELSE directive: Format: {$ELSE} Description: Determines whether the code snippet between the directive to {$ENDIF} should be compiled or ignored by judging the ifxxx of the prefix.

7. ENDIF directive: Format: {$ENDIF} Description: In conjunction with IFXXX, specify the end position of the source snippet for the conditional precompiled segment.

Two Example:

Write examples to compile without code snippets by predefined different compilation symbols.

1. Create a new Delphi project and add a button to the form on the UNIT1 unit.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.