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 ...
随机推荐
- JAVA中循环删除list中元素的方法总结(同上篇)
印象中循环删除list中的元素使用for循环的方式是有问题的,但是可以使用增强的for循环,然后今天在使用时发现报错了,然后去科普了一下,再然后发现这是一个误区.下面就来讲一讲..伸手党可直接跳至文末 ...
- Linux常用命令大全(分类)
首先按ESC键回到命令模式: vi保存文件有不同的选项,对应于不同的命令,你可以从下面的命令中选择一个需要的::w 保存文件但不退出vi :w file 将修改另外保存到file中,不退出vi:w! ...
- Python模拟登陆TAPD
因为在wiki中未找到需要的数据,查询也很迷,打算用python登录tapd抓取所需项目下的wiki数据,方便查找. 2018-9-30 19:12:44 几步走 模拟登录tapd 抓取wiki页左侧 ...
- uva-10382-贪心
题意:对于长为L,宽为W的矩形草地,需要对它进行浇水,总共有n个水龙头,给每个水龙头的浇水半径,和位置.求覆盖整个草地需要的最小水龙头数量. 如图,把浇水的面积转换成矩形,然后就和区间覆盖一样了,直接 ...
- 63.(原65)纯 CSS 创作一个摇摇晃晃的 loader
原文地址:https://segmentfault.com/a/1190000015424389 修改后地址:https://scrimba.com/c/cqKv4VCR HTML code: < ...
- java中异常处理
看到一篇异常处理的好文章: Java异常处理机制主要依赖于try,catch,finally,throw,throws五个关键字. try 关键字后紧跟一个花括号括起来的代码块,简称try块.同理:下 ...
- 使用AsyncTask类实现简单的异步处理操作
AsyncTask: 1.这是一种相比Handler更轻量级的处理异步任务的工具类 2.它和Handler类一样,都是为了不影响主线程(UI)而使用的((注:UI的更新只能在主线程中完成) 3.这个工 ...
- 通过adb启动app应用
由于某些原因,我需要自动启动雷电模拟器里面的一个应用.(利用Windows任务计划) 怎么自启动雷电模拟器就不用说了,很简单. 自启动app我倒是不熟悉,我没用安卓方面的知识.再官网论坛上面查到了相关 ...
- K8s之Etcd
Etcd是一个开源的.高可用的.分布式的键值对数据存储系统,提供共享配置.服务的注册和发现.etcd与zookeeper相比算是轻量级系统,两者的一致性协议也一样,etcd的raft比zookeepe ...
- vue.js建立一个简单的表格
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...