(page requirements)
Downloads

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 );
begin
  MessageBox(
    0, 
    PChar( sMsg ), 
    'Notice', 
    MB_OK );
end;
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 );
begin
  MessageDlg( 
    sMsg,
    mtInformation,
    [mbOk],
    0 );
end;
Listing #2 : Delphi code. Download msgdlg (0.23 KB).
 
 
Applicable Keywords : Delphi, Delphi 2.x, Delphi 3.x, Functions
 
 
 
Copyright © 2009 Chami.com. All Rights Reserved. | Advertise | Created in HTML Kit editor