官术网_书友最值得收藏!

Assertions

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 such statements and they will not generate any code. You can for example use this to remove assertions from the release code. Even if any argument to Assert contains a function call, this function will not be called when assertions are turned off.

主站蜘蛛池模板: 黄浦区| 靖宇县| 万源市| 余江县| 广安市| 醴陵市| 苍梧县| 桃源县| 长汀县| 潢川县| 大埔县| 汨罗市| 宣城市| 青岛市| 泰宁县| 鸡东县| 阿坝| 宜宾县| 辽源市| 灵台县| 临武县| 襄垣县| 康马县| 高要市| 图木舒克市| 托克逊县| 廉江市| 寿阳县| 河源市| 封开县| 申扎县| 盘锦市| 奉节县| 高阳县| 泰顺县| 清镇市| 石家庄市| 新巴尔虎右旗| 南康市| 南昌市| 邹平县|