Wednesday, March 2, 2011

Handy little Write() equivalent for Windows programs

Delphi comes with a very well integrated debugger, but sometimes it's more appropriate and easier to display something in the middle of your program rather than stepping through many lines of code.

Since you can't use the "Write()" functions in Windows programs (unless it's a console mode program), here's a handy little function which you can use to display a string. The reason for calling "x()" x is simple -- typing out long names is the last thing you want to take time for when debugging programs.
uses Windows;

procedure x( sMsg : string );
    PChar( sMsg ),
    MB_OK );
Listing #1 : Delphi code. Download msgbox (0.23 KB).
You could also call Delphi's "MessageDlg()" function, rather than calling Windows' "MessageBox()" function as in the above example. The difference, as far as program size goes, is that programs using the Dialogs unit directly or indirectly would be larger than those programs that aren't. So, if you're not already using the Dialogs unit, you may want to use the "MessageBox()" function to save some space.
uses Dialogs;

procedure x( sMsg : string );
    0 );
Listing #2 : Delphi code. Download msgdlg (0.23 KB).

Twitter Delicious Facebook Digg Stumbleupon Favorites More

Design by Kang Iwan K-sev | Thank's for your visit To My Site - Ridwan Mulyana | Cibeureum