Sign in Join
Wiki copytemporary

$IF: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: $IF

OldNewLine
1+The
2+
3+``` pascal
4+{$if …}
5+```
6+
7+directive can be used in [[Conditional compilation|conditional compilation]].
8+
9+``` pascal
10+// pointermath directive did not exist prior FPC 3.0.0
11+{$if FPC_VERSION > 2}
12+ // pointer arithmetics is bad. very bad
13+ {$pointermath off}
14+{$endif}
15+```
16+
17+Also, enable you to write complex conditions that you cannot do with the
18+
19+``` pascal
20+{$ifdef …}
21+```
22+
23+,
24+
25+And there are two bool functions\[defined/undefined\] that can be mixedup with \[and/or\] logic operators, For example:
26+
27+``` pascal
28+//Befor you need write these conditions to check some conditions:
29+{$define SOMETHING}
30+{$define SOMETHINGELSE}
31+{$ifdef SOMETHING}//Union $IfDef to check multiple conditions
32+ {$ifdef SOMETHINGELSE}
33+ {$ModeSwitch advancedrecords}
34+ {$endif}
35+{$endif}
36+
37+//But with the {$IF} you can check conditions together:
38+{$if defined(SOMETHING) and defined(SOMETHINGELSE)}//simple and readabl instead of union {$IFDef}`s
39+ {$ModeSwitch advancedrecords}
40+{$endif}
41+
42+{$if defined(somthing) or defined(somethingelse)}
43+ //Whatever you need!
44+{$endif}
45+
46+{$if undefined(what) and defined(somethingelse)}
47+ //Just for note, Another usage!
48+{$endif}
49+```
50+
51+---
52+*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).*

Back to history