Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Delphi/Windows gizmo of the week

236 views
Skip to first unread message

Alessandro Federici

unread,
Jan 26, 2007, 2:51:25 PM1/26/07
to
Hi everyone,
it has been a while but I am still alive and kicking :)

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


Captain Jake

unread,
Jan 26, 2007, 3:16:23 PM1/26/07
to

"Alessandro Federici" <no...@none.com> wrote in message
news:45ba5b8c$1...@newsgroups.borland.com...

> Hi everyone,
> it has been a while but I am still alive and kicking :)

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?


Ingvar Anderberg

unread,
Jan 26, 2007, 5:53:32 PM1/26/07
to
"Alessandro Federici" <no...@none.com> skrev


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

Remy Lebeau (TeamB)

unread,
Jan 26, 2007, 6:05:18 PM1/26/07
to

"Alessandro Federici" <no...@none.com> wrote in message
news:45ba5b8c$1...@newsgroups.borland.com...

> 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


David Clegg

unread,
Jan 26, 2007, 6:37:43 PM1/26/07
to
Alessandro Federici wrote:

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

Abdullah Kauchali

unread,
Jan 27, 2007, 3:39:58 AM1/27/07
to

"Remy Lebeau (TeamB)"

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

Sounds really useful, thanks Remy! Going to try that out this weekend! :)


Alessandro Federici

unread,
Jan 28, 2007, 10:47:29 AM1/28/07
to
"Captain Jake" <ja...@NOSPAMJsNewsreader.com> wrote in message
news:45ba6170$1...@newsgroups.borland.com...
[..]

> A lot of us have been wondering what you've been doing lately. You used to
> be quite active here, you know!

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


Alessandro Federici

unread,
Jan 28, 2007, 10:48:25 AM1/28/07
to
"David Clegg" <dcl...@gmail.com> wrote in message
news:xn0f1pi2...@newsgroups.borland.com...
[..]

> However, I now prefer to use CodeSite,

Well, my tip was the poor man's CodeSite :)


Charles McAllister

unread,
Jan 28, 2007, 1:11:34 PM1/28/07
to

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!

Carl Caulkett

unread,
Jan 28, 2007, 1:17:19 PM1/28/07
to
Alessandro Federici wrote:

Hey Alef,

Good to see you here. How's it going?

--
Cheers,
Carl

David Clegg

unread,
Jan 28, 2007, 2:32:49 PM1/28/07
to
Alessandro Federici wrote:

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

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

John Jacobson

unread,
Jan 28, 2007, 5:14:56 PM1/28/07
to
"Alessandro Federici" <no...@none.com> wrote in message
news:45bcc55b$1...@newsgroups.borland.com...

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

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.


Robin

unread,
Jan 28, 2007, 5:37:46 PM1/28/07
to
Alessandro Federici wrote:
> 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!


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

Alessandro Federici

unread,
Jan 28, 2007, 10:31:26 PM1/28/07
to
"Charles McAllister" <cha...@avimark.net> wrote in message
news:45bce723$1...@newsgroups.borland.com...
[..]

> good to see you back here!

Thanks!


Alessandro Federici

unread,
Jan 28, 2007, 10:32:19 PM1/28/07
to
"Carl Caulkett" <car...@dircon.co.uk> wrote in message
news:45bc...@newsgroups.borland.com...
[..]

> Good to see you here. How's it going?

Very good, tx :) See my reply to John for more info on what I am doing these
days.


Dan Barclay

unread,
Jan 28, 2007, 11:15:21 PM1/28/07
to
That's a good tip, and I've used it from time to time in a non-Delphi
environment with SysInternal's DebugView.

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

Alessandro Federici

unread,
Jan 29, 2007, 12:46:49 AM1/29/07
to
"Dan Barclay" <D...@MVPs.org> wrote in message
news:45bd7654$3...@newsgroups.borland.com...
[..]

> Still a good tip, but if you can expand on the "OutputDebugString will do
> nothing" part it would be helpful.

Actually that is what MS says (see SDK help). I know nothing more about this
as I haven't profiled it.

Regards,
Alessandro


Lars Black

unread,
Jan 29, 2007, 2:34:24 AM1/29/07
to
"Alessandro Federici" <no...@none.com> wrote in message
news:45bcc593$1...@newsgroups.borland.com...

>
> Well, my tip was the poor man's CodeSite :)

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


Clément Doss

unread,
Jan 29, 2007, 8:48:02 AM1/29/07
to
Hi Alessandro,

>
> 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!

Iman L Crawford

unread,
Jan 29, 2007, 11:37:35 AM1/29/07
to
"John Jacobson" <jake@j[nospam]snewsreader.com> wrote in news:45bd202b$1
@newsgroups.borland.com:

> I will most likely be moving to Colorado this summer for a job in the
> Boulder area, that I started last week.

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


Iman L Crawford

unread,
Jan 29, 2007, 11:40:02 AM1/29/07
to
"Alessandro Federici" <no...@none.com> wrote in news:45ba5b8c$1
@newsgroups.borland.com:

> it has been a while but I am still alive and kicking :)

Nice tip, and it's good to hear from you again.

--
Iman


Captain Jake

unread,
Jan 29, 2007, 2:17:09 PM1/29/07
to
"Iman L Crawford" <ilcrawford.at.hotmail.dot.com> wrote in message
news:Xns98C76C195...@207.105.83.66...

> congrats. I really like CO, but ever since our friends got divorced and
> moved away from Colorado Springs we haven't been back.

I'd probably die of sheer politcal terror in Colorado Springs, given my
views.


Markus.Humm

unread,
Jan 29, 2007, 2:58:43 PM1/29/07
to
Clément Doss schrieb:
[snip]

>
> 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!
>
Hello,

with your approach you always have the overhead of that procedure call.
If I'm not mistaken...

Greetings

Markus

Mitch

unread,
Jan 29, 2007, 3:50:13 PM1/29/07
to
John Jacobson wrote:
> 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.
>
Congratulations, it'll be good to have some more Delphi programmers here
in Colorado. I work down the road in Golden. Unless you're moving from
CA or Seattle you'll find Boulder a bit pricey but I'm sure you already
know that.

Mitch Wolberg,
RockWare, Inc.

Robert Giesecke

unread,
Jan 29, 2007, 4:03:53 PM1/29/07
to
Markus.Humm wrote:
>
> with your approach you always have the overhead of that procedure call.
> If I'm not mistaken...
>

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.

Captain Jake

unread,
Jan 29, 2007, 3:53:12 PM1/29/07
to

"Mitch" <mitc...@rockware.com> wrote in message
news:45be5dc7$1...@newsgroups.borland.com...

> Congratulations, it'll be good to have some more Delphi programmers here
> in Colorado. I work down the road in Golden. Unless you're moving from CA
> or Seattle you'll find Boulder a bit pricey but I'm sure you already know
> that.

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.


Bob Moore

unread,
Jan 29, 2007, 5:19:11 PM1/29/07
to
>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.

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.

Serge Dosyukov (Dragon Soft)

unread,
Jan 29, 2007, 5:35:47 PM1/29/07
to
we'll miss you ;o)

Serge Dosyukov (Dragon Soft)

unread,
Jan 29, 2007, 5:38:35 PM1/29/07
to
<g>You didn't know about it? 8^0????</g>

Captain Jake

unread,
Jan 29, 2007, 5:40:16 PM1/29/07
to

"Serge Dosyukov (Dragon Soft)" <pooh996.gmail.com> wrote in message
news:45be...@newsgroups.borland.com...

> we'll miss you ;o)

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.


Serge Dosyukov (Dragon Soft)

unread,
Jan 29, 2007, 11:07:09 PM1/29/07
to
I doubt I will have a time for the next few months to do anything not
related directly...
it is sad that we loosing people, but it is life...
You are welcome to stop by you know where ;o) and we can have a lunch ;o)

Alessandro Federici

unread,
Jan 30, 2007, 10:51:57 AM1/30/07
to
"Serge Dosyukov (Dragon Soft)" <pooh996.gmail.com> wrote in message
news:45be7732$1...@newsgroups.borland.com...

> <g>You didn't know about it? 8^0????</g>

Well, do you know how to turn a fox in an elephant?


Rick Carter

unread,
Jan 30, 2007, 11:56:22 AM1/30/07
to
Captain Jake wrote:
>I'd probably die of sheer politcal terror in Colorado Springs, given my
>views.

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

Iman L Crawford

unread,
Jan 30, 2007, 11:24:26 AM1/30/07
to
"Rick Carter" <cart...@despammed.com> wrote in news:45bf6d17$1
@newsgroups.borland.com:

> But John Jacobson posted that he is looking forward to moving there.

he is looking forward to Boulder CO. Colorado Springs is home to some
fundamental christian groups.

--
Iman


Captain Jake

unread,
Jan 30, 2007, 6:31:45 PM1/30/07
to
"Iman L Crawford" <ilcrawford.at.hotmail.dot.com> wrote in message
news:Xns98C869DE...@207.105.83.66...

> he is looking forward to Boulder CO. Colorado Springs is home to some
> fundamental christian groups.

And a lot of military and government people too.


Rick Carter

unread,
Jan 31, 2007, 11:21:16 AM1/31/07
to
>Well, do you know how to turn a fox in an elephant?

The fox is inside the elephant, and it needs to be turned?

Andrew Fiddian-Green

unread,
Jan 31, 2007, 10:50:44 AM1/31/07
to
> Well, do you know how to turn a fox in an elephant?

No. Please tell...


Serge Dosyukov (Dragon Soft)

unread,
Jan 31, 2007, 11:51:48 AM1/31/07
to
Make balloon out of it? ;o)

David Clegg

unread,
Jan 31, 2007, 6:37:49 PM1/31/07
to
Alessandro Federici wrote:

> 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

Nick Hodges (CodeGear)

unread,
Jan 31, 2007, 6:49:13 PM1/31/07
to
David Clegg wrote:

> 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

I.P. Nichols

unread,
Feb 1, 2007, 1:50:03 AM2/1/07
to
"David Clegg" wrote:
> Alessandro Federici wrote:
>
>> Well, do you know how to turn a fox in an elephant?
>
> Marry it? At least thats what Google tells me.

Someone said that marrage can turn a fox into a cow that never forgets. ;-)

Alessandro Federici

unread,
Feb 1, 2007, 11:09:21 AM2/1/07
to
"Andrew Fiddian-Green" <nn@dd> wrote in message
news:45c0ba97$1...@newsgroups.borland.com...

>> Well, do you know how to turn a fox in an elephant?
> No. Please tell...

Marry her :)


Alessandro Federici

unread,
Feb 1, 2007, 11:09:47 AM2/1/07
to
"David Clegg" <dcl...@gmail.com> wrote in message
news:45c1...@newsgroups.borland.com...

>> Well, do you know how to turn a fox in an elephant?
> Marry it? At least thats what Google tells me.

LOL yup!


David Clegg

unread,
Feb 1, 2007, 2:31:13 PM2/1/07
to
Alessandro Federici wrote:

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

Captain Jake

unread,
Feb 1, 2007, 3:21:31 PM2/1/07
to

"David Clegg" <dcl...@gmail.com> wrote in message
news:45c24001$1...@newsgroups.borland.com...

> Alessandro Federici wrote:
>
>> 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.


0 new messages