问题
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?
回答1:
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.
回答2:
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.
回答3:
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.
回答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.
回答5:
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.
来源:https://stackoverflow.com/questions/11218434/how-to-view-output-of-outputdebugstring