Delphi compilation instructions (2): More methods for using conditional statements

Source: Internet
Author: User
1. $ ifdef is equivalent to $ if defined (...):
They end with: $ endif and $ ifend. In this example, ver200 is the ID of Delphi 2009.
Begin {$ ifdef ver200} showmessage ('this is Delphi 2009 '); {$ endif} {$ if defined (ver200)} showmessage ('this is Delphi 2009 '); {$ ifend} end;
 

2. $ ifndef is equivalent to $ if not defined (...):

They end with: $ endif and $ ifend. In this example, ver150 is the ID of Delphi 7.
Begin {$ ifndef ver150} showmessage ('this is not Delphi 7'); {$ endif} {$ if not defined (ver150)} showmessage ('this is not Delphi 7 '); {$ ifend} end;
 

3. You can use or and:

Begin {$ define AAA} {$ define BBB} {$ if defined (AAA) or defined (BBB)} showmessage ('condition identifier AAA and one of BBB defines '); {$ ifend} {$ if defined (AAA) and defined (BBB)} showmessage ('condition identifiers AAA and BBB both define '); {$ ifend} end;
 

4. You can use constants in the system unit:

I tested many CONSTANTS IN THE SYSTEM unit.
Begin showmessage (floattostr (compilerversion); {in Delphi 2009, compilerversion = 20.0 }{$ if compilerversion >=17.0} showmessage ('this is a version of Delphi 2005 or later '); {$ ifend} end;
 

5. Use $ ifopt to determine the compilation switch:

Delphi is quite fun. 26 letters are arranged into different switch commands (use Ctrl + O to view them, of course, more than these switch commands );
$ Ifopt can determine whether these commands are enabled.
This command is not very commonly used. I checked the VCL source code of 2009 and used it six times in total.
Begin {$ ifopt B +} showmessage ('COMMAND B has opened '); {$ else} showmessage ('COMMAND B closed '); {$ endif} {$ B +} {$ ifopt B +} showmessage ('OK! '); {$ Endif} end;
 

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.