$IF: what changed
Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.
| Old | New | Line | |
|---|---|---|---|
| 1 | - | ||
| 2 | - | ||
| 3 | - | ||
| 4 | - | ||
| 5 | - | ||
| 6 | - | ||
| 7 | - | ||
| 1 | + | The `{$if …}` directive can be used in [[Conditional compilation|conditional compilation]]. | |
| 8 | 2 | ||
| 9 | 3 | ``` pascal | |
| 10 | 4 | // pointermath directive did not exist prior FPC 3.0.0 | |
| 11 | 5 | {$if FPC_VERSION > 2} | |
| 12 | 6 | // pointer arithmetics is bad. very bad | |
| 13 | 7 | {$pointermath off} | |
| 14 | 8 | {$endif} | |
| 15 | 9 | ``` | |
| 16 | 10 | ||
| 17 | - | ||
| 18 | - | ||
| 19 | - | ||
| 20 | - | ||
| 21 | - | ||
| 22 | - | ||
| 23 | - | ||
| 11 | + | Also, enable you to write complex conditions that you cannot do with the `{$ifdef …}`, | |
| 24 | 12 | ||
| 25 | 13 | And there are two bool functions\[defined/undefined\] that can be mixedup with \[and/or\] logic operators, For example: | |
| 26 | 14 | ||
| 27 | 15 | ``` pascal | |
| 28 | 16 | //Befor you need write these conditions to check some conditions: | |
| 29 | 17 | {$define SOMETHING} | |
| 30 | 18 | {$define SOMETHINGELSE} | |
| 31 | 19 | {$ifdef SOMETHING}//Union $IfDef to check multiple conditions | |
| 32 | 20 | {$ifdef SOMETHINGELSE} | |
| 33 | 21 | {$ModeSwitch advancedrecords} | |
| 34 | 22 | {$endif} | |
| 35 | 23 | {$endif} | |
| 36 | 24 | ||
| 37 | 25 | //But with the {$IF} you can check conditions together: | |
| 38 | 26 | {$if defined(SOMETHING) and defined(SOMETHINGELSE)}//simple and readabl instead of union {$IFDef}`s | |
| 39 | 27 | {$ModeSwitch advancedrecords} | |
| 40 | 28 | {$endif} | |
| 41 | 29 | ||
| 42 | 30 | {$if defined(somthing) or defined(somethingelse)} | |
| 43 | 31 | //Whatever you need! | |
| 44 | 32 | {$endif} | |
| 45 | 33 | ||
| 46 | 34 | {$if undefined(what) and defined(somethingelse)} | |
| 47 | 35 | //Just for note, Another usage! | |
| 48 | 36 | {$endif} | |
| 49 | 37 | ``` | |
| 50 | 38 | ||
| 51 | 39 | --- | |
| 52 | 40 | *From the Free Pascal wiki, page "$IF", as it stood on 2022-08-06 after a change by Kai Burghardt, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* |
