14

I want to use OutputDebugString() in my application and then have the option to show it in a separate viewer when the application is deployed in the field.

That is to say, I don't want to have to change a flag and rebuild my .exe to turn debugging on and off.

Googling around, it seems like DebugView should handle that, but neither it, nor TraceTool show any output from this code.

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}


procedure TForm1.FormCreate(Sender: TObject);
begin
   OutputDebugString(PChar('Hello, wurld'));
end;

end.

I have read the documentation, to no avail, and see that others have had similar problems, but have not posted a solution.

Is there a solution?

8

5 Answers 5

30

The DebugView tool works fine; only be sure to launch your application directly (without the Delphi IDE or another debugger attached).

Anyway, the natural way to view the OutputDebugString output for a Delphi application is to use the Delphi IDE and the Event Log Window.

Enter image description here

Enter image description here

Sign up to request clarification or add additional context in comments.

11 Comments

+1 can you confirm that XE2 starter edition doesn't have an event log viewer? embarcadero.com/products/delphi/delphi-feature-matrix seems to indicate so. Presumably, then, I can't view my output from the IDE, but only when I run it stand-alone?
I can't believe which the Event Log Windows isn't part of the Delphi Starter edition :(
But it looks that way in the feature matix, right? And I can't find it on the menu ...
Yes, it seems a Delphi Starter limitation.
Hmmm, I do understand that Embarcadero had to cut features for the starter (else no one would have bought anything else). But if the IDE doesn't handle it, couldn't they have made it so that outher programs, such as DebugView could handle OutputDebugString() while I am steeping through my my app in the IDE?
|
9

GExperts has a debug viewer and a unit you add to your application that will do this for you, even in XE2 Starter. See the DebugIntf unit and the GExpertsDebugWindow.exe application that it includes. These work under XE2 Starter (and pretty much all other versions of Delphi).

GExperts also includes tons of other IDE and editor enhancements that are great, and of course they've been around forever, so they're pretty solid tools.

4 Comments

It doesn't run on a PC which has never had Delphi installed (can't find RTL60.BPL). I have posted to the GExperts mailing list, but so mfar had no reply.
It's built with runtime packages. If the version number in the BPL you give isn't a typo (I think it should be 160, not 60), you have a very early version installed (60 was around Delphi 6, IIRC). If it is 160, you can find that in your Windows\System32 folder, and put it in the same folder as you put the debug viewer executable. It's one of Delphi's distributable runtime libraries, so you're allowed to ship it with the app. You'll need VCL160 and VCLX160, too.
Oops, it was indeed 160, not 60. I had already copied that BPL, but did not know to copy the other two. That works nicely. Thank you, as always, for your excellent help.
Careful, GExpers is known to crash the IDE: quality.embarcadero.com/browse/RSP-34374
5

CnWizards contains a tool, CnDebugViewer.exe, which can capture OutputDebugString (should be run as administrator in Windows 7).

Not like DbgView, CnDebugViewer can create separated tabs for different applications.

CnPack contains an unit, CnDebug.pas. Using this unit, you can trace typed objects, collections, exceptions, memdump, etc. With CnDebug.pas, you also can set whether to autostart CnDebugViewer, whether dump to file while sending debug messages, etc.

Comments

4

One problem with using OutputDebugString is that other programs may also be using it, cluttering your log: Debugging OutputDebugString calls in Delphi.

You could use CodeSite Express, which we've been very happy with in day-to-day use: http://www.raize.com/devtools/codesite/Default.asp.

3 Comments

That's only a problem if you're using a tool that intentionally collects messages from other programs and then offers no way to filter them. Plain old debuggers won't have that problem because OutputDebugString usually only sends messages to the single program debugging it. The SysInternals tool uses a different, non-standard technique for collecting messages without becoming a debugger for all processes. But it also allows filtering. So there's really no problem at all.
Code Site does not appear to be free :-(
CS Express is included in XE2 & XE3. I've been using the full version for years; outstanding tool, much more useful than it may appear at first glance.
2

In my version of XE5, I had to enable the "Output Messages" option under:

Tools > Options > Debugger Options > Event Log

I don't recall disabling it.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.