ESC in MessageDlg lazarus / 31-LCL ---------------------------------------------------------------------- Walmir · 2014-08-26 17:31 I have the following code in a BeforeDelete event of a TField: Code: [Select]procedure TdmData.qryServBeforeDelete(DataSet: TDataSet); begin   if Application.MessageBox('Do qyou want to delete this service?','Confirme',   MB_YESNO + MB_ICONQUESTION + MB_DEFBUTTON2) = IDNO then     Abort; end; When the user hits the ESC key, the record is deleted... Is there  a logic error in my code? It was ported from Delphi without modifications. ---------------------------------------------------------------------- howardpc · 2014-08-26 18:18 Quote from: Walmir on August 26, 2014, 07:31:19 pmIs there  a logic error in my code? Yes, you miss the case that the returned value is IDCANCEL (pressing Esc). So change it to Code: [Select]if Application.MessageBox(...) in [IDNO, IDCANCEL] then   Abort; ---------------------------------------------------------------------- Bart · 2014-08-26 18:22 The native MessageDlg function on Vista+ return IDCANCEL when you close the dialog using the escape key. And IDCANCEL <>IDNO, so the record will be deleted. Your Delphi might not use the native Vista+ dialogs (it depends on Delphi version), and so it may return IDNO on Escape key (this is how non-native (as in: we (LCL) draw the dialog ourselfs, using standard form en buttons) MessageDlg works). You shoud test for IDYES and then and only then delete the record (as you should have doe in the first place IMHO). Bart ---------------------------------------------------------------------- taazz · 2014-08-26 18:23 Quote from: howardpc on August 26, 2014, 08:18:21 pmQuote from: Walmir on August 26, 2014, 07:31:19 pmIs there  a logic error in my code? Yes, you miss the case that the returned value is IDCANCEL (pressing Esc). So change it to Code: [Select]if Application.MessageBox(...) in [IDNO, IDCANCEL] then   Abort; or simple Code: [Select]if Application.MessageBox(...) <> IDYES then   Abort;