Home

Message Boxes: Show Message

 

Fundamental Message Boxes

 

Introduction

A message box is a relatively small dialog box used to display a message and provide one or more buttons. Here is an example of a message box:

Message Box

A message box is used to provide information to the user or to request a decision (from the user). By clicking the button or one of the buttons (if the message box displays more than one), the user makes a decision and the program continues.

Message boxes are created from built-in functions from the VCL and the Win32 library. The necessary functions shipped with the compiler.

 

 

Message Showing

The ShowMessage() function provides the most fundamental of Embarcadero’s message boxes. 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:

//---------------------------------------------------------------------------
WINAPI _tWinMain(HINSTANCE hInstance,
	           HINSTANCE hPrevInstance,
		   LPSTR lpCmdLine,
		   int nCmdShow)
{
	ShowMessage(L"Welcome to the Sellers Bank.");
	return 0;
}
//---------------------------------------------------------------------------

This would produce:

Message Box

The string can also come from a control on the application. The string can also be a combination of other strings:

//---------------------------------------------------------------------------
WINAPI _tWinMain(HINSTANCE hInstance,
				   HINSTANCE hPrevInstance,
				   LPSTR lpCmdLine,
				   int nCmdShow)
{
	String strName = "Andy Bossal";
	String strMessage = " is not in our records.";
	ShowMessage("The name " + strName + strMessage);
	return 0;
}
//---------------------------------------------------------------------------

This would produce:

As with other message boxes that we will study here, to display the message on various lines of text, you can separate lines using the C/C++ new line constant represented by '\n'. The VCL provides another alternative. To separate lines of text, you can use the sLineBreak constant. Here is an example:

//---------------------------------------------------------------------------
WINAPI _tWinMain(HINSTANCE hInstance,
				   HINSTANCE hPrevInstance,
				   LPSTR lpCmdLine,
				   int nCmdShow)
{
	AnsiString strMessage = "Your record has been registered";
	AnsiString strCountry = "Country Name: Australia";
	AnsiString strCity    = "City to visit: Melbourne";
	AnsiString strFinal   = "Have a nice strip.";

	ShowMessage(strMessage + sLineBreak + strCountry + sLineBreak +
			strCity + sLineBreak + strFinal);
	return 0;
}
//---------------------------------------------------------------------------

This would produce:

Message Box

     

 

 

 

Home Copyright © 2010-2016, FunctionX