begin
  {$ IFDEF MSWINDOWS}
    ShowMessage ('Windows');
  {$ ENDIF}

  {$ IFDEF LINUX}
    ShowMessage ('Linux');
  {$ ENDIF}
end ;


2.Custom condition identifier (DEFINE):
The following example customizes the condition identifier: WanYi; Identifiers and the instructions that define them are not case sensitive, but people generally use uppercase.

begin
  {$ DEFINE WANYI}
  {$ IFDEF WanYi}
    ShowMessage ('Identifier WanYi is defined');
  {$ ELSE}
    ShowMessage ('Identifier WanYi is undefined');
  {$ ENDIF}
end ;


3.Cancel condition identifier definition (UNDEF):

begin
  {$ DEFINE WANYI}
  {$ IFDEF WANYI} 
    ShowMessage ('Confirm identifier WanYi is defined');
  {$ ENDIF}

  {$ UNDEF WANYI}
  {$ IFDEF WANYI} 
    ShowMessage ('Reconfirm whether identifier WanYi is defined');
  {$ ENDIF}
end ;


4.Easy way to cancel definition:
Add anything before the $ in {$ …} to make it a “comment”, for example: {. $}

begin
   {. $ DEFINE WANYI}
  {$ IFDEF WANYI} 
    ShowMessage ('Confirm identifier WanYi is defined');
  {$ ENDIF}

  {. $ UNDEF WANYI}
  {$ IFDEF WANYI} 
    ShowMessage ('Reconfirm whether identifier WanYi is defined');
  {$ ENDIF}
end ;


5.Special attention when debugging compilation instructions:
Delphi has a common sense: if the unit code has not changed, the corresponding dcu will not be regenerated!

Therefore, in order to have accurate debugging results, use Shift + F9 to compile the current project before execution, and then run;
forcing compile all relevant units also Yes, method: Project-> Build all project.

Of course, it is also very convenient to modify the code, such as putting a space in the code and then returning.

6.Test predefined Debug and Release:
When we create a new project, Delphi defaults to the Debug state. When we publish software, we should switch to the Release state.
There are differences in the compilation instructions in the two states . The dcu released in the Release state or The exe will be smaller and more optimized.

Switching between Debug and Release:
Enter Project Manager-> Build Configurations, double-click on Debug or Release, or activate from the right button.

The following code can detect this change, but note that the above mentioned Go to Shift + F9 or Project-> Build all project.

begin
  {$ IFDEF DEBUG}
    ShowMessage ('Debug mode');
  {$ ENDIF}

  {$ IFDEF RELEASE}
    ShowMessage ('Release mode');
  {$ ENDIF}
end ;


7.Where are the compilation instructions written ?:
Compilation instructions can be written anywhere on the code page, but sometimes they are different in different areas of the code; for

example: {$ APPTYPE GUI} and {$ APPTYPE CONSOLE} can only be written in the project file.

{$ APPTYPE GUI } And {$ APPTYPE CONSOLE} represent window project and console project respectively.
Among them, {$ APPTYPE GUI} is the default, so it is rarely seen.

It can even be embedded in the line of code. For example, ActnColorMaps unit has this sentence:

begin 
  SystemParametersInfo (SPI_GETFLATMENU,0, {$ IFNDEF CLR} @ {$ ENDIF}FlatMenus, 0);
end ;


8.Valid range of condition identifier:
Delphi’s pre-defined condition identifiers are global. We use {$ DEFINE …} to customize local identifiers.

How to customize global identifiers?
Project-> Options …-> Optional Set Delphi Compiler-> Click Conditional defines the small button on the right-> Add.

But this is still different from the system predefined, we can only use it for the current file.

How to define the identifier that can be used for each file?
From the Project-> Options … definition, immediately select Default in the lower left corner.

This is still different from the system pre-defined, because this can only control the future files, regardless of the existing files.
How … no way a.

other compiler directives, such as provided in the Debug or Release is also like this; that is to say: each file has a relatively independent compilation settings

see Project -> Options … immediately understood set of compiler directives There are two ways:
1. Use {$ …} to embed in the code;
2. Set from Project-> Options …

But embedding in the code is sometimes irreplaceable, such as conditional compilation, which is now discussed.

9.How many compilation instructions ?:
What I’m talking about now is only conditional compilation. The most practical application is switch compilation; execute the shortcut Ctrl + O + O on any code page , and then look at the top …
The following are the default settings:

{$ A8, B-, C +, D +, E-, F-, G +, H +, I +, J-, K-, L +, M-, N-, O +, P +, Q-, R-, S-, T-, U-, V +, W-, X +, Y +, Z1}
{$ MINSTACKSIZE $ 00004000}
{$ MAXSTACKSIZE $ 00100000}
{$ IMAGEBASE $ 00400000}
{$ APPTYPE GUI}
{$ WARN SYMBOL_DEPRECATED ON}
{$ WARN SYMBOL_LIBRARY ON}
{$ WARN SYMBOL_PLATFORM ON}
{$ WARN SYMBOL_EXPERIMENTAL ON}
{$ WARN UNIT_LIBRARY ON}
{$ WARN UNIT_PLATFORM ON}
{$ WARN UNIT_DEPRECATED ON}
{$ WARN UNIT_EXPERIMENTAL ON}
{$ WARN HRESULT_COMPAT ON}
{$ WARN HIDING_MEMBER ON}
{$ WARN HIDDEN_VIRTUAL ON}
{$ WARN GARBAGE ON}
{$ WARN BOUNDS_ERROR ON}
{$ WARN ZERO_NIL_COMPAT ON}
{$ WARN STRING_CONST_TRUNCED ON}
{$ WARN FOR_LOOP_VAR_VARPAR ON}
{$ WARN TYPED_CONST_VARPAR ON}
{$ WARN ASG_TO_TYPED_CONST ON}
{$ WARN CASE_LABEL_RANGE ON}
{$ WARN FOR_VARIABLE ON}
{$ WARN CONSTRUCTING_ABSTRACT ON}
{$ WARN COMPARISON_FALSE ON}
{$ WARN COMPARISON_TRUE ON}
{$ WARN COMPARING_SIGNED_UNSIGNED ON}
{$ WARN COMBINING_SIGNED_UNSIGNED ON}
{$ WARN UNSUPPORTED_CONSTRUCT ON}
{$ WARN FILE_OPEN ON}
{$ WARN FILE_OPEN_UNITSRC ON}
{$ WARN BAD_GLOBAL_SYMBOL ON}
{$ WARN DUPLICATE_CTOR_DTOR ON}
{$ WARN INVALID_DIRECTIVE ON}
{$ WARN PACKAGE_NO_LINK ON}
{$ WARN PACKAGED_THREADVAR ON}
{$ WARN IMPLICIT_IMPORT ON}
{$ WARN HPPEMIT_IGNORED ON}
{$ WARN NO_RETVAL ON}
{$ WARN USE_BEFORE_DEF ON}
{$ WARN FOR_LOOP_VAR_UNDEF ON}
{$ WARN UNIT_NAME_MISMATCH ON}
{$ WARN NO_CFG_FILE_FOUND ON}
{$ WARN IMPLICIT_VARIANTS ON}
{$ WARN UNICODE_TO_LOCALE ON}
{$ WARN LOCALE_TO_UNICODE ON}
{$ WARN IMAGEBASE_MULTIPLE ON}
{$ WARN SUSPICIOUS_TYPECAST ON}
{$ WARN PRIVATE_PROPACCESSOR ON}
{$ WARN UNSAFE_TYPE OFF}
{$ WARN UNSAFE_CODE OFF}
{$ WARN UNSAFE_CAST OFF}
{$ WARN OPTION_TRUNCATED ON}
{$ WARN WIDECHAR_REDUCED ON}
{$ WARN DUPLICATES_IGNORED ON}
{$ WARN UNIT_INIT_SEQ ON}
{$ WARN LOCAL_PINVOKE ON}
{$ WARN MESSAGE_DIRECTIVE ON}
{$ WARN TYPEINFO_IMPLICITLY_ADDED ON}
{$ WARN RLINK_WARNING ON}
{$ WARN IMPLICIT_STRING_CAST ON}
{$ WARN IMPLICIT_STRING_CAST_LOSS ON}
{$ WARN EXPLICIT_STRING_CAST OFF}
{$ WARN EXPLICIT_STRING_CAST_LOSS OFF}
{$ WARN CVT_WCHAR_TO_ACHAR OFF}
{$ WARN CVT_NARROWING_STRING_LOST OFF}
{$ WARN CVT_ACHAR_TO_WCHAR OFF}
{$ WARN CVT_WIDENING_STRING_LOST OFF}
{$ WARN XML_WHITESPACE_NOT_ALLOWED ON}
{$ WARN XML_UNKNOWN_ENTITY ON}
{$ WARN XML_INVALID_NAME_START ON}
{$ WARN XML_INVALID_NAME ON}
{$ WARN XML_EXPECTED_CHARACTER ON}
{$ WARN XML_CREF_NO_RESOLVE ON}
{$ WARN XML_NO_PARM ON}
{$ WARN XML_NO_MATCHING_PARM ON}