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

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.

主站蜘蛛池模板: 博客| 高雄县| 凌海市| 黑水县| 南川市| 登封市| 蒙阴县| 沁水县| 台东县| 深圳市| 大田县| 贺兰县| 青阳县| 旅游| 睢宁县| 麟游县| 南召县| 乌鲁木齐市| 阿瓦提县| 开封县| 瓮安县| 特克斯县| 沙河市| 伊春市| 沐川县| 灵台县| 辽阳市| 龙岩市| 西平县| 桂东县| 砚山县| 化隆| 临城县| 新宾| 北辰区| 通州区| 合作市| 淳化县| 水城县| 台中县| 肃宁县|