user328146
user328146

Reputation:

How do I use OutputDebugString to print a message that's in a string variable?

I recently had to do some changes in some Delphi code. Therefore, I have some basics questions:

  1. Generally, how do I output to the console?
  2. How do I output to the console with fx that is a string variable?

I started using OutputDebugString, but I couldn't get it working with a variable.

Upvotes: 14

Views: 48929

Answers (3)

Thorsten Engler
Thorsten Engler

Reputation: 2371

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 ).

If you have Delphi XE, that should already come with an somewhat reduced functionality version of CodeSite.

Upvotes: 4

Tony
Tony

Reputation: 10347

You can write a wrapper function to take care of the variables passed to OutputDebugString as it expects a 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 Basics site. I use it a lot :)

Upvotes: 30

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 article will guide you through the process, though it's in C++).

Upvotes: 0

Related Questions