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

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.

主站蜘蛛池模板: 宾阳县| 德清县| 安远县| 延边| 迁西县| 维西| 洛隆县| 临湘市| 沁源县| 永仁县| 邵东县| 如皋市| 淳安县| 闵行区| 台东县| 九龙县| 平阳县| 灌阳县| 玉门市| 颍上县| 隆昌县| 宜君县| 冀州市| 右玉县| 福建省| 修武县| 遵化市| 丰台区| 丽水市| 清丰县| 慈利县| 汉源县| 共和县| 板桥市| 特克斯县| 晋中市| 台北市| 二手房| 康定县| 丰顺县| 光山县|