November 2019
Beginner to intermediate
674 pages
15h
English
The Assertions compiler options enables or disables code generation for Assert statements. You can use compiler directives {$ASSERTIONS ON} and {$ASSERTIONS OFF} to turn this option on or off in the code. Short forms of this directive are rather cryptic {$C+} and {$C-}.
Delphi allows us to use runtime checks in the code in a form of Assert statements. Assert will check whether the first parameter evaluates to false and will raise an exception with the (optional) second parameter in an exception message, if that is true.
The following statement will raise an exception if variable i is smaller than zero:
Assert(i >= 0, 'Expecting a positive value here');
If you turn code generation for assertions off, the compiler will just skip ...
Read now
Unlock full access