The ShowMessage() Function

The ShowMessage() function provides the most fundamental message box of Borland’s applications. This function takes one string argument and does not return any value. It is used to display a message to the user who acknowledges it by clicking the OK button. The syntax of the ShowMessage() function is

void __fastcall ShowMessage(const AnsiString Message);

A message box created with the ShowMessage() function uses the name of the project as its caption. The message to display is a string that can be provided by the developer. Here is an example:

 


//---------------------------------------------------------------------------
void __fastcall TForm1::btnShowMsgClick(TObject *Sender)
{
    ShowMessage("Welcome to the Sellers Bank.");
}		
//---------------------------------------------------------------------------

The string can also derive from another control such as the content of an edit box, a memo, or any text control. Here is an example:

//---------------------------------------------------------------------------
void __fastcall TForm1::btnMsgFromEditClick(TObject *Sender)
{
    ShowMessage(edtMessage->Text);
}
//---------------------------------------------------------------------------

The string can also be a combination of other strings:

//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
    ShowMessage("The name " + AnsiString("\"")
                + edtMessage->Text + AnsiString("\"")
                + " is not in our records.");
}
//---------------------------------------------------------------------------

If the message is long and you want to span more than one line, you can split it using the new line operator:

//---------------------------------------------------------------------------
void __fastcall TForm1::btnShowMsgClick(TObject *Sender)
{
    ShowMessage("Please fill out your Time Sheet before leaving.\n"
                "Make sure you sign and send it to Human Resources");
}
//---------------------------------------------------------------------------

 

 



Copyright © 2001-2007 FunctionX, Inc.