![]() |
Show Message |
|
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: ![]() |
|
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. |
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: procedure ShowMessage(const Msg: string); 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: ShowMessage('Welcome to the Sellers Bank.')
This would produce:
The string can also come from a control on the application. The string can also be a combination of other strings: procedure TForm1.btnMessageBoxClick(Sender: TObject); var strName, strMessage : String; begin strName := 'Andy Bossal'; strMessage := ' is not in our records.'; ShowMessage('The name ' + strName + strMessage); end; 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 sLineBreak constant. Here are examples: procedure TForm1.btnMessageBoxClick(Sender: TObject);
var strMessage, strCountry, strCity, strFinal : String;
begin
strMessage := 'Your record has been registered';
strCountry := 'Country Name: Australia';
strCity := 'City to visit: Melbourne';
strFinal := 'Have a nice strip.';
ShowMessage(strMessage + sLineBreak + strCountry + sLineBreak +
strCity + sLineBreak + strFinal);
end;
This would produce:
|
|
|
||
| Home | Copyright © 2010 FunctionX, Inc. | |
|
|
||