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);
直接將結果
uj5u.com熱心網友回復:
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);
uj5u.com熱心網友回復:
抱歉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 關閉表單了,不知道問題出在哪里,該如何解決呢
uj5u.com熱心網友回復:
varFCanClose :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;
uj5u.com熱心網友回復:
樓上的方法試過了,點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之后會再次彈出訊息,不過只有一瞬間,表單關閉)
uj5u.com熱心網友回復:
Platform Without ACloseDialogProc With ACloseDialogProcWindows Blocking Blocking
OS X Blocking Blocking
iOS Blocking Non-blocking
Android Non-blocking
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/24117.html
