Delphi 中 断言 Assert 用法
来源:互联网 发布:c语言趣味编程 编辑:程序博客网 时间:2024/06/04 19:13
procedure Assert(expr : Boolean [; const msg: string]);
用法: Assert(表达式,[显示信息]);
如果为假, assert会产生一个EAssertionFailed异常,显示信息为:
Debugger Exception Notification
Project Project2.exe raised exception class EAssertionFailed with Message'AAA
(C:/Users/tangjianbao/Desktop/test/Project2.dpr line 23)'. Process stopped. use Step or Run to Contine.
当你不想再使用这些检查时,可以使用 {$ASSERTIONS OFF/ON } 或 {$C-} 编译指令.
要想使Assert在整个项目中失效, 关闭Project Options | Compiler | Assertion 选项。
Delphi7 Help Code: (将下列代码拷贝 到 ConSole 可以直接运行,调试一下,体会会更深刻)
program Project2;
{$APPTYPE CONSOLE}
{ Defining OLDSTYLE for the compilation allows old-style
runtime error handling to occur rather than the new
exception-based method. If the old style is used, then
the user-supplied string is not displayed. }
{$IFNDEF OLDSTYLE}
uses
SysUtils;
{$ENDIF}
type
TStorage = class(TObject)
FData: string;
property Data: string read FData write FData;
end;
procedure ModifyStorage(AStorage: TStorage; const s: string);
begin
Assert(AStorage <> nil, 'AAA');
AStorage.Data := s;
end;
var
Storage: TStorage;
begin
Storage := TStorage.Create;
try
ModifyStorage(Storage, 'Hello world');
finally
Storage.Free;
end;
// The following call is buggy and triggers the Assert
ModifyStorage(nil, 'Ooops');
end.
- Delphi 中 断言 Assert 用法
- Delphi 中ASSERT用法
- Delphi 中ASSERT用法
- java中assert(断言)用法
- 断言ASSERT的用法
- assert()断言的用法
- assert 断言用法总结
- assert() 断言的用法
- 断言(ASSERT)的用法
- 断言(ASSERT)的用法
- 断言(ASSERT)的用法
- 断言(ASSERT)的用法
- 断言(ASSERT)的用法
- 断言(ASSERT)的用法
- 断言(ASSERT)的用法
- 断言(ASSERT)的用法
- 断言(ASSERT)的用法
- 断言(ASSERT)的用法
- 【转】asp.net 客户端回调通知
- 战争磨盘十二:身在曹营
- js执行回调函数,执行成功后执行另外程序
- 关于xml删除节点的问题
- C/C++数组名与指针区别深入探索
- Delphi 中 断言 Assert 用法
- Java常用方法大全--不断更新中。。。
- 开发WebService两种开源工具CXF和 Axis2的比较
- JS闭包深入详解
- menuconfig Linux Error: curses.h: No such file or directory Problem Solution
- Linux文件系统的缓存机制
- 设立数据表中的主键
- Red Hat Enterprise Linux AS4下安装Oracle10g
- 开博--2010.05.17