RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
Dialogs.ShowMessage Function

Displays a message box with an OK button.

Pascal
procedure ShowMessage(const Msg: string);
C++
ShowMessage(const AnsiString Msg);

Dialogs

Call ShowMessage to display a simple message box with an OK button. The name of the application's executable file appears as the caption of the message box.  

Msg parameter is the message string that appears in the message box.  

Params lists the values to insert into Msg if the Msg string includes formatting specifiers. For more information about how messages are formatted, see Format Strings. 

Params_size is the index of the last value in Params (one less than the number of elements).

Note: To display a message in a message box with other buttons, or with an icon, use the MessageDlg function.
Note: If the user types Ctrl+C in the message box, the text of the message is copied to the clipboard.
 

C++ Examples: 

 

/*
The following example uses an edit control and a button on a
form. When the button is clicked, the current directory is
searched for the filename specified in the edit control. A
message box indicates whether the file is found.
*/
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  AnsiString asFileName = FileSearch(Edit1->Text, GetCurrentDir());
  if (asFileName.IsEmpty())
    ShowMessage(AnsiString("Couldn't find ") + Edit1->Text + ".");
  else
    ShowMessage(AnsiString("Found ") + asFileName + ".");
}

void __fastcall TForm1::FormCreate(TObject *Sender)
{
  Label2->Caption = GetCurrentDir();
}

 

Delphi Examples: 

{
The following example uses an edit control and a button on a
form. When the button is clicked, the current directory is
searched for the filename specified in the edit control. A
message box indicates whether the file is found.
}
procedure TForm1.Button1Click(Sender: TObject);
var
  FileToFind: string;
begin
  FileToFind := SysUtils.FileSearch(Edit1.Text, GetCurrentDir);
  if FileToFind = '' then
    ShowMessage('Couldn''t find ' + Edit1.Text + '.')
  else
    ShowMessage('Found ' + FileToFind + '.');
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Label2.Caption := GetCurrentDir;
end;

 

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!