string 如何使用 OutputDebugString 打印字符串变量中的消息?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4873356/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I use OutputDebugString to print a message that's in a string variable?
提问by Tony
I recently had to do some changes in some Delphi code. Therefore, I have some basics questions:
我最近不得不对一些 Delphi 代码进行一些更改。因此,我有一些基本问题:
- Generally, how do I output to the console?
- How do I output to the console with
fx
that is a string variable?
- 一般来说,我如何输出到控制台?
- 如何
fx
使用字符串变量输出到控制台?
I started using OutputDebugString
, but I couldn't get it working with a variable.
我开始使用OutputDebugString
,但我无法让它与变量一起工作。
回答by Tony
You can write a wrapper function to take care of the variables passed to OutputDebugString
as it expects a PChar.
您可以编写一个包装函数来处理传递给OutputDebugString
它期望 PChar 的变量。
Something like:
就像是:
procedure DebugMsg(const Msg: String);
begin
OutputDebugString(PChar(Msg))
end;
There is a useful reference for debugging techniques here.
没有为调试技术提供有益的参考这里。
And if your Delphi is a bit rusty there's the ever useful Delphi Basicssite. I use it a lot :)
如果您的 Delphi 有点生疏,那么这里有一个非常有用的Delphi Basics站点。我经常使用它:)
回答by Thorsten Engler
In addition to the 2 answers you got about OutputDebugString() and WriteLn(), for debugging there is a better solution: CodeSite from Raize Software (see http://www.raize.com/DevTools/CodeSite/Default.asp).
除了您获得的关于 OutputDebugString() 和 WriteLn() 的 2 个答案之外,还有一个更好的调试解决方案:来自 Raize Software 的 CodeSite(请参阅http://www.raize.com/DevTools/CodeSite/Default.asp)。
If you have Delphi XE, that should already come with an somewhat reduced functionality version of CodeSite.
如果您有 Delphi XE,那么应该已经带有 CodeSite 功能有所减少的版本。
回答by Eugene Mayevski 'Callback
If you have a console application, just use write() and writeln() global functions. If you have a GUI application and want to create a separate console windows, things go tricky (this articlewill guide you through the process, though it's in C++).
如果您有控制台应用程序,只需使用 write() 和 writeln() 全局函数。如果您有一个 GUI 应用程序并且想要创建一个单独的控制台窗口,事情就会变得棘手(本文将指导您完成整个过程,尽管它是用 C++ 编写的)。