MessageBox also allows you to display multiple buttons and know which the user pressed. This is very usefull for limited yes/no type user interaction.
To do:
- Add a button to our form (set its Caption to MessageBox2).
- Double click on the button to bring up the editor.
- Type lines 2 and 3 from the code listing above begin.
- Type Lines 5 and 6 between the begin and end.
- Run and test the program.
Notes:
- Notice we declared sAns to be an integer. Then assigned the return value from MessageBox to it.
- Because Pascal is a highly typed language, we must use methods like IntToStr to convert a value to the correct type for the given method (as in line 6).
1. procedure TForm1.Button3Click(Sender: TObject);
2. var
3. iAns : Integer;
4. begin
5. iAns := Application.MessageBox('Is this fun?', 'Question', MB_YESNO);
6. ShowMessage(IntToStr(iAns));
7. end;
|