Message Alerts on Multiple Devices

Written by Sarina D on Posted in UI

Easily add various styles of message alerts to your Appmethod apps, both standard one-button information box style, and multiple button input box styles that allow various confirmations. The code is the same across Windows, Mac, iOS and Android.

 

C++:

void __fastcall TForm2::btnMultipleButtonAlertClick(TObject *Sender)
{
	/* Show a multiple-button alert that triggers different code blocks according to
		your input */
	switch (MessageDlg("Choose a button:", TMsgDlgType::mtInformation,
		TMsgDlgButtons() << TMsgDlgBtn::mbYes << TMsgDlgBtn::mbNo << TMsgDlgBtn::mbCancel , 0))
	{
		case mrYes :
			ShowMessage("You choose Yes");
			break;
		case mrNo:
			ShowMessage("You choose No");
			break;
		case mrCancel:
			ShowMessage("You choose Cancel");
			break;
	}
} 

Object Pascal:

procedure TMessageAlertsForm.btnMultiButtonAlertClick(Sender: TObject);
begin
//Show a multiple-button alert that triggers different code blocks according to your input 
  case MessageDlg('Choose a button:', System.UITypes.TMsgDlgType.mtInformation,
    [
      System.UITypes.TMsgDlgBtn.mbYes,
      System.UITypes.TMsgDlgBtn.mbNo,
      System.UITypes.TMsgDlgBtn.mbCancel
    ], 0) of
 // Detect which button was pushed and show a different message 
    mrYES:
      ShowMessage('You chose Yes');
    mrNo:
      ShowMessage('You chose No');
    mrCancel:
      ShowMessage('You chose Cancel');
  end;
end;

 

Demo Projects:

Message Alerts with C++

Message Alerts with Object Pascal

 

Tags: Mobile UI iOS Android Object Pascal C++ Message Alerts



About
Gold User, Rank: 5, Points: 558

Check out more tips and tricks in this development video: