Here's something useful for all those people using either dirty ShowMessages
or TMemos to log debug messages: OutputDebugString(<your string>), contained
in Windows.pas.
What this will do is put the <your string> text in Delphi's event log panel
(Ctrl+Alt+V or View/Debug Windows/Event Log). If the application has no
debugger and the system debugger is not active, OutputDebugString will do
nothing. Handy little procedure!
Enjoy,
Alessandro Federici
A lot of us have been wondering what you've been doing lately. You used to
be quite active here, you know!
Still doing Delphi?
Thank for that tip!
I had to check the "Output Messages" checkbox
in Tools/Options/Debugger Options/Event Log
before the string showed up.
It works in BCBuilder too.
/ia
> If the application has no debugger and the system debugger is
> not active, OutputDebugString will do nothing.
The other nice thing about OutputDebugString() is that there are
third-party tools available, such as SysInternal's DebugView, that can
intercept OutputDebugString() at runtime, even on remote mchines, when
your application is not running inside any debugger.
Gambit
Welcome back, Alessandro!
> Here's something useful for all those people using either dirty
> ShowMessages or TMemos to log debug messages: OutputDebugString(<your
> string>), contained in Windows.pas.
Yeah, I've been using that technique for years.
However, I now prefer to use CodeSite,
http://www.raize.com/DevTools/CodeSite/Default.asp, which gives the
same effect and so much more. You can output a whole bucketload of
information, including complex object structures. It can be used as a
application logging system by persisting to file, or having the
information sent to a viewer client running remotely. And all of this
can be enabled/disabled at run-time.
--
Cheers,
David Clegg
dcl...@gmail.com
http://cc.codegear.com/Author/72299
QualityCentral. The best way to bug CodeGear about bugs.
http://qc.codegear.com
"I know I'm not usually a praying man, but if you're up there, please
Superman, help me!" - Homer Simpson
Sounds really useful, thanks Remy! Going to try that out this weekend! :)
I've been working for a company (somewhat related to RO) which produces law
enforcement/home land security software for the past year. They are in PA
and I will move there soon.
> Still doing Delphi?
Mostly, altough we are considering ASP.NET for a new piece of the system
Alessandro
Well, my tip was the poor man's CodeSite :)
its a nice technique, but i've found that these calls to outputdebugstring can clutter up the code a bit. its too easy to forget to remove them.
fortunately there is an option when you set a breakpoint, to have the breakpoint emmit a string to the event log instead of actually stopping execution.
right-click on your breakpoint, go to breakpoint properties, then click 'advanced', then uncheck 'Break', and in the 'Log message' box type in the expression you wish to appear in the event log.
good to see you back here!
Hey Alef,
Good to see you here. How's it going?
--
Cheers,
Carl
> Well, my tip was the poor man's CodeSite :)
Yep, and a good tip it was too. And as Remy has already pointed out, it
is a great technique to use when accompanied by a third party debug
viewer. My favourite is DebugView from Microsoft (nee SysInternals).
http://www.microsoft.com/technet/sysinternals/utilities/debugview.mspx
One gotcha with this approach however, is that if you run your app in
the debugger then the IDE Message window will 'hijack' the output and
display the messages there. This can be a little confusing to the
OutputDebugString n00b.
--
Cheers,
David Clegg
dcl...@gmail.com
http://cc.codegear.com/Author/72299
QualityCentral. The best way to bug CodeGear about bugs.
http://qc.codegear.com
"A woman is a lot like a refrigerator. 6 feet tall, 300 pounds ... it
makes ice. " - Homer Simpson
Interesting. (I'd wish you luck, but with your skills you don't need it.)
I will most likely be moving to Colorado this summer for a job in the
Boulder area, that I started last week. I was out there this past week, will
be again this next week, and will probably be out there about once a month
until I move. They make shrink-wrapped software. It is Delphi, turning into
C++ over time. I'm actually quite excited. I love it out there in Boulder
(it is right against the foothills of the Rocky Mountains), and the firm
looks like an excellent place to work. I've always wanted to move to
Colorado since I was out there for a few weeks in the early 80's.
Cool!
I love groups like this; You just don't know what you don't know :-)
Thanks Allessandro.
--
Robin.
Australian Bridal Accessories := http://www.bridalbuzz.com.au
Thanks!
Very good, tx :) See my reply to John for more info on what I am doing these
days.
However, re:
> If the application has no debugger and the system debugger is not active,
> OutputDebugString will do nothing.
My understanding is that it's flinging the message when you call the API,
regardless of whether something is there to catch it. Is there something
going on to short circuit that process that I'm not aware of? The
performance hit of preparing and flinging the message still exists.
Still a good tip, but if you can expand on the "OutputDebugString will do
nothing" part it would be helpful.
Thanks,
Dan
"Alessandro Federici" <no...@none.com> wrote in message
news:45ba5b8c$1...@newsgroups.borland.com...
Actually that is what MS says (see SDK help). I know nothing more about this
as I haven't profiled it.
Regards,
Alessandro
Check out TraceTool at http://www.codeproject.com/csharp/TraceTool.asp.
Works on multiple platforms, so you can use the same tool from Delphi and
ASP.NET.
Cheers,
Lars
>
> What this will do is put the <your string> text in Delphi's event log panel
> (Ctrl+Alt+V or View/Debug Windows/Event Log). If the application has no
> debugger and the system debugger is not active, OutputDebugString will do
> nothing. Handy little procedure!
Thanks for the tip.
Those links can help a little.
http://msdn2.microsoft.com/en-us/library/aa363362.aspx
http://www.unixwiz.net/techtips/outputdebugstring.html
Here is how I use OutputDebugstring. (I have not the unit here with me, just writing
up to show an example)
unit _DebugUnit;
// Uncomment this line to use Outputdebugstring
{.DEFINE _DEBUGGING}
procedure DU_OutputDebugString( const aMsg : string );
implementation
uses windows;
procedure DU_OutputDebugString( const aMsg : string );
begin
{$IFDEF _DEBUGGING}
OutputDebugString( PAnsiChar(aMsg) );
{$ENDIF}
end;
initialization
DU_OutputDebugString('*** OutputDebugstring is active ***');
I just define or undefine _DEBUGGING.
Cool!
congrats. I really like CO, but ever since our friends got divorced and
moved away from Colorado Springs we haven't been back. Good luck on your
move.
--
Iman
Nice tip, and it's good to hear from you again.
--
Iman
I'd probably die of sheer politcal terror in Colorado Springs, given my
views.
with your approach you always have the overhead of that procedure call.
If I'm not mistaken...
Greetings
Markus
Mitch Wolberg,
RockWare, Inc.
I would even go further by *not* using a const parameter.
Do you really want to send a pointer to one of your precious strings to an external debugger?
I think the call itself isn't all that hard a hit though. Except you send lot and lots and lots of stuff.
Yeah, we are expecting to get a house anout 20-30 minutes away from Boulder
for that very reason. Actually, once you get away from Boulder itself, the
housing is quite affordable in the area.
I've used this for years as well, but here's couple of little extra
tips :
Don't forget to add a newline (#10) for more readable output. I have a
wrapper function that timestamps the debug string, adds a text process
identifier and a newline.
There's a bug in windows 2000 - OutputDebugString doesn't work
properly unless you have administrative privileges on the machine.
I use the venerable DBWin32 for catching the output, but there's quite
a few tools available. Even on apps which have their own debug
facilities built in, I always have an option to copy the output to
OutputDebugString, because it can be VERY handy to have the output
from multiple apps serialised into a single stream - I've had a couple
of bugs which involved interaction between apps that I could ONLY find
and fix with this trick.
You really ought to organize a Milwaukee Delphi Users Group in my honor
then! <g> Dan Miser has left the Delphi realm, and Clay Shannon is too busy
to organize one, so the prior organizers of the old Delphi users group are
not likely to pick it back up.
Well, do you know how to turn a fox in an elephant?
But John Jacobson posted that he is looking forward to moving there.
Is this your multiple personality syndrome manifesting itself again?
Rick Carter
cart...@despammed.com
Chair, Delphi/Paradox SIG, Cincinnati PC Users Group
--- posted by geoForum on http://delphi.newswhat.com
he is looking forward to Boulder CO. Colorado Springs is home to some
fundamental christian groups.
--
Iman
And a lot of military and government people too.
The fox is inside the elephant, and it needs to be turned?
No. Please tell...
> Well, do you know how to turn a fox in an elephant?
Marry it? At least thats what Google tells me.
--
Cheers,
David Clegg
dcl...@gmail.com
http://cc.codegear.com/Author/72299
QualityCentral. The best way to bug CodeGear about bugs.
http://qc.codegear.com
> Marry it?
I, personally, haven't got the slightest idea what you are talking
about. ;-)
--
Nick Hodges
Delphi Product Manager - CodeGear
http://blogs.codegear.com/nickhodges
Someone said that marrage can turn a fox into a cow that never forgets. ;-)
Marry her :)
LOL yup!
> LOL yup!
Well, on the slight but remote possibility that my fox may come
foraging in here one day, I must say I wholeheartedly disagree with
this. :-)
My fox never made the predicted transformation. At 43 she has even more sex
appeal than when we got married.