delphi 中OutputDebugString 函数的妙用(转载)
原文地址 https://www.peganza.com/delphi-and-outputdebugstring.html
Ever wanted to monitor your Delphi application in realtime, and be able to view log messages? Of course you can always run in full debug mode inside RAD Studio IDE. Another way is to output log messages, for example to a text file. You can also use the OutputDebugString function.
An advantage of this approach is that it impacts your application as little as possible. You don't have to care about file handling. Just call a function.
The OutputDebugString function is defined in the Win32 API, in the RTL unit Winapi.Windows.
You simply call it from your code like this:
1
2
3
4
5
6
7
8
9
10
11
|
.. uses Winapi . Windows; .. var Msg : string ; begin OutputDebugString( 'This is my message' ); Msg := 'This is another log message' ; OutputDebugString( PChar (Msg)); .. |
If you call OutputDebugString repeatedly or in a loop, it may cause some performance overhead. So make sure that calls to OutputDebugString are not included in your release version. To avoid it, you can use a conditional compilation directive, like:
1
2
3
4
5
|
.. (*$IFDEF ODS*) OutputDebugString( 'This is my message' ); (*$ENDIF*) .. |
Only activate the compilation directive "ODS" when you want to log messages this way. Also, consider creating a wrapper function for the call to OutputDebugString, so your code will be easier to read and maintain. Something like this:
1
2
3
4
5
6
|
procedure DebugODS( const Msg : string ); begin (*$IFDEF ODS*) OutputDebugString( PChar (Msg)); (*$ENDIF*) end ; |
If you run from within RAD Studio IDE, the log messages will be displayed in the output window.
But if you run standalone, a good possibility is to use the free DebugView application (dbgview.exe) available from SysInternals (Microsoft). Information from their web page:
DebugView is an application that lets you monitor debug output on your local system, or any computer on the network that you can reach via TCP/IP. It is capable of displaying both kernel-mode and Win32 debug output, so you don't need a debugger to catch the debug output your applications or device drivers generate, nor do you need to modify your applications or drivers to use non-standard debug output APIs.
The image above shows some sample debug output from our Pascal Analyzer application.
As you see in the screenshot, messages are prefixed with a timestamp and a process ID.
Read more about DebugView and download it here.
delphi 中OutputDebugString 函数的妙用(转载)的更多相关文章
- delphi 中OutputDebugString 函数的妙用(使用DebugView或者Pascal Analyzer软件,在运行过程中就能监视和捕捉日志,而且通过网络就能监视)
原文地址 https://www.peganza.com/delphi-and-outputdebugstring.html 曾经想要实时监控您的Delphi应用程序,并能够查看日志消息吗?当然,您始 ...
- Delphi中的函数指针判断是否为空
delphi函数指针 只有@@p才代表了函数指针本身的地址 assigned(p) 判断是否为空 或者用 @p=nil 来判断函数指针是不是为空 Delphi中的函数指针实际上就是指针,只是在使用 ...
- Delphi中 StrToIntDef函数的用法
Delphi中 StrToIntDef函数的用法:比如我要判断一个文本框里输入的字符串能不能转换为integer类型,如果能,则返回转换后的整型数据,如果不能,则返回整数0,那么我就可以用strtoi ...
- delphi中move函数的正确理解(const和var一样,都是传地址,所以Move是传地址,而恰恰不是传值)太精彩了 good
我们能看到以下代码var pSource,pDest:PChar; len: integer;.......................//一些代码Move(pSource,pDest,l ...
- Oracle中SYS_CONNECT_BY_PATH函数的妙用 ;
Oracle 中SYS_CONNECT_BY_PATH函数是非常重要的函数,下面就为您介绍一个使用SYS_CONNECT_BY_PATH函数的例子,实例如下: 数据准备: ),b )); ', 'A' ...
- (转)PHP中extract()函数的妙用
近日在看一个牛人的代码时,看到一个非常好用的函数:extract(),它的主要作用是将数组展开,键名作为变量名,元素值为变量值,可以说为数组的操作提供了另外一个方便的工具,比方说,可以很方便的提取$_ ...
- (转)PHP中extract()函数的妙用
近日在看一个牛人的代码时,看到一个非常好用的函数:extract(),它的主要作用是将数组展开,键名作为变量名,元素值为变量值,可以说为数组的操作提供了另外一个方便的工具,比方说,可以很方便的提取$_ ...
- sql server中quotename()函数的用法(转载)
操作sql server尤其是写存储过程时,要用到各种各样的函数,今天就总结一个quotename()的用法.1.语法: quotename('character_string'[,'quote_ch ...
- PHP中extract()函数的妙用
看cakephp 2.3.8的源代码,很多地方都用 到 compact('name', 'response'); extract($status, EXTR_OVERWRITE); 这样的代码.com ...
随机推荐
- 6.8 出口条件循环:do while
while循环和for循环都是入口条件循环,即在循环的每次迭代之前检查测试条件,所以有可能根本不执行循环体中的内容.C语言还有出口条件循环(exit-condition loop),即在循环的每次迭代 ...
- 在mysql数据库中创建Oracle数据库中的scott用户表
在mysql数据库中创建Oracle数据库中的scott用户表 作者:Eric 微信:loveoracle11g create table DEPT ( DEPTNO int(2) not null, ...
- 开源ERP系统Odoo搭建文档
本文参考链接地址: https://devecho.com/v/209/ https://www.cnblogs.com/wxylog/p/6386974.html 什么是Odoo 为什么选择Odoo ...
- scrollview嵌套recyclerview卡顿现象
方式一xml: android:nestedScrollingEnabled="false" <android.support.v7.widget.RecyclerView ...
- org.apache.ibatis.builder.IncompleteElementException: Could not find result map java.util.HashMap
这样的配置有问题吗? <select id="getFreightCollectManagementList" resultMap="java.util.HashM ...
- Open SuSE中自定义的环境变量
针对与其它发行版本的Linux,网络上给出的添加环境变量的位置都是在/etc/profile文件中添加.在Open SuSE中也有/etc/profile文件,不过从该文件的前几行注释可以看出,官方建 ...
- 01 Python 逻辑运算
#基本运算符 #and or not #优先级 ()>not>and>or #and or not print(2>1 and 1<4 or 2<3 and 9&g ...
- ABAP-FTP-配置
1.FTP配置: 设置FTP参数:IP地址.账号.密码.路径.RFC目标. 设置数据表:数据表及字段明细,设置查询字段及报表输出字段. 2.操作界面 3.程序 ZFID0003_ETL_FTP 主程序 ...
- 总结http状态码和200,304状态码
状态码 响应类别 中文意思 1XX 信息性状态码(Informational) 服务器正在处理请求 2XX 成功状态码(Success) 请求已正常处理完毕 3XX 重定向状态码(Redirec ...
- Linux命令:read
在shell中,内建(builtin)命令read,格式如下: read [-ers] [-a aname] [-d delim] [-i text] [-n nchars] [-N nchars] ...