1. Computing
in Delphi TIPS :: Delphi's ShowMessage procedure, defined in the dialogs.pas unit, displays a message in a dialog box, waits for the user to click an OK button.

I'm using the ShowMessage procedure frequently while developing applications as a "debugging" tool to display values of various variables, properties, function results.

A downside of the ShowMessage is that it only accepts a string parameter - where variables tend to be integers, bools, floats, etc. :)

Read the full article to learn how to Overload ShowMessage to accept Integer, Boolean, Float, ...

Related:

Comments
January 6, 2011 at 5:20 pm
(1) Jørn E. Angeltveit says:

This is a great, neat trick.

You could also use a shorter procedure name, like procedure Sm(S: String), just to save some typing when calling.

And even smarter: You could create some overrided procedures with multiple parameters, like:


procedure Sm(S: String; I: Integer);
begin
ShowMessage(S + ': ' + IntToStr(I));
end;

that way you can make some additional comments:


Sm('RandomValue', Random(1000));

January 6, 2011 at 6:21 pm
(2) Linas says:

There is no need to overload ShowMessage when there is ShowMessageFmt. It fits all my needs. E.g.:
ShowMessageFmt(‘String %S, Integer: %D’,['Test', 123]);

January 11, 2011 at 4:59 pm
(3) debugger? says:

What’s wrong with using the debugger and IDE property where you can inspect values or variables etc, you also have

OutputDebugString, also means your less likely to leave showmessage statements in the code by accident!

Leave a Comment

Line and paragraph breaks are automatic. Some HTML allowed: <a href="" title="">, <b>, <i>, <strike>

©2014 About.com. All rights reserved.