Show: Delphi C++
Display Preferences

System.Assert

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

procedure Assert(Condition: Boolean; [ Message: String ]); overload;
procedure Assert(Condition: Boolean; [ Message: String ]); overload;

Properties

Type Visibility Source Unit Parent
procedure public System.pas System System

Description

Tests whether a Boolean expression is true.

In Delphi code, use Assert as a debugging tool to test that conditions assumed to be true are never violated. Assert provides an opportunity to intercept an unexpected condition and halt a program rather than allow execution to continue under unanticipated conditions.

Assert takes a Boolean expression and an optional message string as parameters. If the Boolean test fails, Assert raises an EAssertionFailed exception. If a message string was passed to Assert, the exception object is created with that string. Otherwise it is created with a default string indicating that the assertion failed. The message is displayed along with the complete path, filename, and the line number on which Assert failed.

The SysUtils unit causes run-time errors be turned into exceptions. If SysUtils is not used anywhere in your application, you will get a run-time error 227 rather than an EAssertionFailed exception. This run-time error will halt the program.

Because assertions are not usually used in shipping versions of a product, compiler directives are provided to disable the generation of assertion code:

$ASSERTIONS ON/OFF  (long form)
$C +/-  (short form)

These are global switches that affect the entire source file where they occur, regardless of their position in the file. It is not possible to enable and disable assertions for something smaller than a source file. Assertions are on by default.

See Also

Code Examples

Personal tools
In Other Languages
Previous Versions
Assistance