В Андроид рекомендовано вместо просто вызова ShowMessage использовать анонимный метод: ссылка на код
У меня есть такая конструкция:
try
{
//код
}
catch(Exception &E)
{
struct TCloseDialogHandler : public TCppInterfacedObjectTInputCloseDialogProc>
{
void __fastcall Invoke(const System::Uitypes::TModalResult AResult)
{
switch (AResult)
{
case mrYes :
{
Application->Terminate();
//ShowMessage("You chose Yes");
}
break;
case mrNo:
ShowMessage("You chose No");
break;
case mrCancel:
ShowMessage("You chose Cancel");
break;
}
}
};
_di_TInputCloseDialogProc handler = new TCloseDialogHandler();
String MES = L"Error. Class: " + E.ClassName() + L"\nMessage: " + E.Message + L"\nThe program will be closed.";
MessageDlg(MES, TMsgDlgType::mtInformation, TMsgDlgButtons() TMsgDlgBtn::mbYes, 0, handler);
}
Писать во всех catch одно и тоже утомительно.
Правильно ли я создала функцию и правильно ли передаю параметры?
void ExceptionMessage(Exception &E)
{
struct TCloseDialogHandler : public TCppInterfacedObjectTInputCloseDialogProc>
{
void __fastcall Invoke(const System::Uitypes::TModalResult AResult)
{
switch (AResult)
{
case mrYes :
{
Application->Terminate();
//ShowMessage("You chose Yes");
}
break;
case mrNo:
ShowMessage("You chose No");
break;
case mrCancel:
ShowMessage("You chose Cancel");
break;
}
}
};
_di_TInputCloseDialogProc handler = new TCloseDialogHandler();
String MES = L"Error. Class: " + E.ClassName() + L"\nMessage: " + E.Message + L"\nThe program will be closed.";
MessageDlg(MES, TMsgDlgType::mtInformation, TMsgDlgButtons() TMsgDlgBtn::mbYes, 0, handler);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
try
{
//код
}
catch(Exception &E)
{
ExceptionMessage(E);
}
}