One, usage: Assert (expression)
1. If False assert generates a eassertionfailed exception, it is displayed as assertion Failed (C:/src/unit1.pas, [Size=+0]line 34)
2. If you no longer want to use these checks, you can use ($ASSERTIONS OFF) or ($C-) Compile instructions
3. To invalidate the assert for the entire project, close the project Options | Compiler | Assertion option.
II, Delphi Assert () function usage
assert (Assert) is used for conditional testing. Expression expressions can be evaluated, and if the value is False (that is, 0), then it prints an error message to stderr and then terminates the program by calling abort.
Iii. Usage Summary and precautions:
1) Verify the legitimacy of the incoming parameters at the beginning of the function
3) You cannot use a statement that alters the environment, because assert only takes effect in debug, and if you do, you will use the program to run into problems when it is actually running.
4) Assert and subsequent statements should be empty lines to create a logical and visual sense of consistency
Iv. Examples of programs
Procedure Tform1.button1click (Sender:tobject);
Begin
Parameter 1 is false when prompted, parameter 2 is the prompt character
Assert (False, ' This place is wrong! ‘);
End
Delphi Hint Error line number assert (assert)