temp = MsgBox(tempStr, vbCritical, "Can Not Create Directory")
temp = MsgBox("Main Text", vbCritical, "Box Caption")
Delphi
| ShowMessage | The simplest to use. |
| ShowMessagePos | Allows control of the box's xy position. |
| MessageDlg | Provides more control. |
| MessageDlgPos | Allows control of the box's xy position. |
| MessageBox | Provides control of caption and buttons |
ShowMessage(const Msg: string);
ShowMessagePos(const Msg: string; X, Y: Integer);
MessageDlg(const Msg: string; AType: TMsgDlgType;
AButtons: TMsgDlgButtons; HelpCtx: Longint): Word;
MessageBox(Text, Caption: PChar; Flags: Word): Integer;
The following provides a function similar
to the VisualBasic MsgBox function
function TForm1.MsgBox(text, caption: string; Flags: Word): Integer; var tempCharArray1, tempCharArray2: array[0..300] of Char; begin StrPCopy(tempCharArray1, Copy(text, 0, 299)); StrPCopy(tempCharArray2, Copy(caption, 0, 299)); MsgBox := Application.MessageBox(tempCharArray1, tempCharArray2, Flags); end;The following code is copied from the Delphi 5 help. Notice that the conversion of Delphi string constants to PChar is automatic - the conversion of string variables is NOT. The flag constants are directly from the Windows MessageBox help (click See Also / MessageBox). This allows one of 4 icons to be displayed as well as a number of different button configurations. To get a list of acceptable choices, with the cursor in the correct spot, press Ctrl-Space and type mb_. :)
if Application.MessageBox( 'Could not open Table1 exclusively - Try again?', 'Open Error', MB_OKCANCEL + MB_DEFBUTTON1) <> IDOK thenThe following returns user entered text
| InputBox | The simplest to use. Has OK and Cancel buttons. |
| InputQuery | Returns the value and a True/False for OK/Cancel. |
Java
JOptionPane.showMessageDialog(frame, "Some message");The following example shows how to select the icon and to specify the text on the buttons.
Object[] options = {"Yes, please",
"No way!"};
int n = JOptionPane.showOptionDialog(frame,
"Would you like green eggs and ham?", // message
"A Silly Question", // title
JOptionPane.YES_NO_OPTION, // how many buttons
JOptionPane.QUESTION_MESSAGE, // icon
null, // used for custom Icon
options, // array of button lables
options[0]); // lable of the default button
Using simple awt technology, Creating a Reusable Message Box discusses how to create standard dialog boxes from Dialog.
Author: Robert Clemenzi - clemenzi@cpcug.org