How can I write to the console window for debugging?

In Windows, the simplest way to output debug information is to use OutputDebugString() and then use an application able to receive that output. The event viewer in the Delphi IDE itself is able to receive that input, or you can use the DebugView application from SysInternals to get output on a system that hasn’t the IDE installed. AFAIK, GExperts has a similar tool too. That’s because a GUI application has not by default a console where to write output, otherwise you have to create one (see Gerry’s answer).

One of OutputDebugString()‘s advantages is that the application will work without problems even if a call slips into a release build (or is if left there intentionally), but be careful then to not output sensitive information, because they can be read using one of the tools above.

You could also create an ad-hoc form (that is, with a memo control) and route output there.

There are also advanced logging facilities like SmartInspect, CodeSite and others.

Leave a Comment