var Check: Boolean;
begin
Check :=False;MessageDlg('确认退出吗?', System.UITypes.TMsgDlgType.mtInformation,[TMsgDlgBtn.mbYes,TMsgDlgBtn.mbn.mbCancel], 0,
     procedure(const AResult: TModalResult)
     begin
       if AResult = mrYES thenCheck :=FalTrueeCancel');
 
  anClose :=Check;
end;同样的代码在Windows平台没什么问题,为什么在安卓平台无法关闭窗口?感觉直接跳过了MessageDlg,如果第一行改成Check :=True,又会直接关闭窗口是哪里错了吗,该怎么写才能正常显示提示框并使得按钮有效呢?改过很多次,要么直接不显示消息框,要么显示了之后点yes还是no不正常,要么都不动,要么都会关闭窗口。麻烦大神们帮忙看看是怎么回事,谢谢!  end);
直接将结果

解决方案 »

  1.   

     TDialogService.MessageDialog('Choose a button:', System.UITypes.TMsgDlgType.mtInformation,
        [System.UITypes.TMsgDlgBtn.mbYes, System.UITypes.TMsgDlgBtn.mbNo, System.UITypes.TMsgDlgBtn.mbCancel],
        System.UITypes.TMsgDlgBtn.mbYes, 0,    // Use an anonymous method to make sure the acknowledgment appears as expected.
        procedure(const AResult: TModalResult)
        begin
          case AResult of
            { Detect which button was pushed and show a different message }
            mrYES:
             //Check :=False;
           //anClose :=Check;
              ShowMessage('You chose Yes');
            mrNo:
              ShowMessage('You chose No');
            mrCancel:
              ShowMessage('You chose Cancel');
          end;
        end);
      

  2.   

    抱歉1楼发出来的时候不知怎的就乱掉了,有些字符删掉了不完整。回复楼上,我用了你发的代码,把他改成了: TDialogService.MessageDialog('确认退出吗?',
     System.UITypes.TMsgDlgType.mtInformation,
        [System.UITypes.TMsgDlgBtn.mbYes, System.UITypes.TMsgDlgBtn.mbNo],
        System.UITypes.TMsgDlgBtn.mbYes, 0,    // Use an anonymous method to make sure the acknowledgment appears as expected.
        procedure(const AResult: TModalResult)
        begin
          case AResult of
            { Detect which button was pushed and show a different message }
            mrYES:
          begin
            Check :=True;
           ShowMessage('You chose Yes');
          end;
            mrNo:
              ShowMessage('You chose No');
          end;
        end); if Check =True then
      begin
      ShowMessage('You chose Yes');
      CanClose :=True;
      end;但是问题来了,这段代码: if Check =True then
      begin
      ShowMessage('You chose Yes');
      CanClose :=True;
      end;本意是判断用户是否在前面的消息中选择了True,但我发现运行时程序会跳过 TDialogService.MessageDialog 直接关闭窗体,如果把 if Check =True then和下面的代码删掉,又可以显示消息框并且可以根据按钮进行不同的提示了。但是这样便没办法CanClose 关闭窗体了,不知道问题出在哪里,该如何解决呢
      

  3.   

    var
     FCanClose :boolean;
    begin
        FCanClose:=false;
        if not FCanClose then
        FMX.Dialogs.MessageDlg(
          'Exit?',
          TMsgDlgType.mtConfirmation,
          [TMsgDlgBtn.mbYes, TMsgDlgBtn.mbNo],
          0,
          procedure(const AResult: TModalResult)
          begin
            if AResult = mrYes then
            begin
              FCanClose := True; // set the field value
              Close; // call close again
            end;
          end );  CanClose := FCanClose;
    end;
      

  4.   

    楼上的方法试过了,点yes的话消息框会闪一下(关闭后又再次弹出,不点no就不能退出),窗体依旧没办法关闭。网上的说法是安卓平台下的消息框都是异步模式的,即弹出消息后不等用户点击按钮就会继续执行下一句。所以我觉得如果把MessageDlg 放在CanClose := FCanClose后面的话可能会被直接跳过,所以改成这样:
    定义全局变量 var FCanClose :Boolean = False;FormCloseQuery事件代码:procedure TMainForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    begin
    CanClose :=FCanClose;MessageDlg('确认退出吗?',
     System.UITypes.TMsgDlgType.mtInformation,
     [System.UITypes.TMsgDlgBtn.mbYes, System.UITypes.TMsgDlgBtn.mbNo], 0,
     procedure(const AResult: TModalResult)
     begin
     if AResult = mrYES then
      begin
      FCanClose :=True;
      Self.Close;
      end;
     end)
    end;问题基本解决(点击yes之后会再次弹出消息,不过只有一瞬间,窗体关闭)
      

  5.   

    Platform  Without ACloseDialogProc  With ACloseDialogProc  
    Windows  Blocking  Blocking  
    OS X        Blocking  Blocking  
    iOS          Blocking  Non-blocking  
    Android                  Non-blocking