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

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.

主站蜘蛛池模板: 莱西市| 永康市| 临沂市| 万盛区| 湖南省| 准格尔旗| 永年县| 沾化县| 通渭县| 岑溪市| 翼城县| 灌阳县| 高州市| 晋中市| 江永县| 微山县| 汉寿县| 合水县| 徐汇区| 南丰县| 德庆县| 大英县| 疏勒县| 崇礼县| 香港 | 北辰区| 许昌县| 信阳市| 连城县| 嵊泗县| 富裕县| 屏东县| 香格里拉县| 离岛区| 荣昌县| 德庆县| 安溪县| 泰和县| 桓台县| 明星| 曲水县|