My homepage: http://www.tommstudio.com/
In Delphi, there are also precompiled instructions similar to C. Although this type of instructions is only valid in the current single file (it may also be that the author does not fully understand the true usage of this type of instructions), this type of instructions is for multi-version. Production work (such as learning the version from the standard version) does have quite good uses.
one. Instruction introduction:
1. DEFINE instruction:
Format: {$DEFINE name}
Description: Used to define a symbol (Symbol) that is valid in the current unit. After the definition, you can use the IFDEF and IFNDEF instructions to determine whether the symbol exists.
2. UNDEF directive:
Format: {$UNDEF name}
Description: Used to cancel a symbol (Symbol) that has been defined in the current unit. This directive is used in conjunction with DEFINE.
3. IFDEF instruction:
Format: {$IFDEF Name}
Description: If the name after the directive is already defined, the code segment is compiled until {$ELSE} or {$ENDIF} after the directive is compiled.
4. IFNDEF instruction:
Format: {$IFNDEF name}
Note: If the name after the directive is not defined, the code segment is compiled until {$ELSE} or {$ENDIF} after the directive is compiled.
5. IFOPT instruction:
Format: {$IFOPT switch}
Note: If the switch after this instruction has been set, compile the code segment until {$ELSE} or {$ENDIF} after the instruction is compiled.
For example:
|
6. ELSE instruction:
Format: {$ELSE}
Note: Determine whether the code segment between the instruction and {$ENDIF} should be compiled or ignored by judging the conditional expression of the prefix Ifxxx.
7. ENDIF instruction:
Format: {$ENDIF}
Description: Cooperate with Ifxxx, specify the end position of the source code segment of the conditional precompiled segment.
two. example:
Write an example to pre-define different compilation symbols to compile without code segments.
1. Create a new Delphi project and add a Button button on the form of Unit1 unit.
2. The program is written as follows:
|
3. After compiling, run, press Button, and you will see that the form title bar shows "AAA". The program compiles the statement a:='AAA'.
4. Change the block of the defined row:
When changed to
|
When compiling and running again, you will see that the form title bar shows "BBB". The program compiles the statement a:='BBB'.
When undefined row or change to
{$DEFINENOTHING} |
If you have another name, compile and run again, you will see that the form title bar shows "Other". The program is only compiled
|
three. How to quickly make and change versions:
Using precompiled instructions, when making multiple versions of the same program, you only need to find out the different units in each version, define the unified version symbol (Symbol) in turn, and then add the conditional precompiled instructions to the program block. Different program parts can be compiled in actual compilation, which can have a good effect on the standardization of the program (defining unified version symbols) and confidentiality (composing different program parts with different versions).
However, since this type of precompiled instruction can only act on the current unit, the inconvenience is that the version symbol cannot be defined once in a common unit, but the unified version symbol must be defined in each unit. Therefore, when replacing the version, It is necessary to make sure that all version symbols have been changed so that the correctness of each version can be ensured. In this regard, you can use the "FindinFiles..." function of DelphiIDE (find strings in multiple files) to find all files that define version symbols. and position, and then change it in turn to ensure that all positions have been corrected.
Generally it looks like this:
|
Also useful:
|
This compilation instruction is an I/O check.
For more specific information, please refer to the relevant information.
|
An error indicates that your code cannot be compiled correctly. Please check your code. If you can compile and pass the code DELPHI by simply entering the code, that's great.