0

On ios (under Delphi), will the main form onDestroy event be called ? I tried and I never see it called, but would like to have a confirmation.

Dan
  • 10,531
  • 2
  • 36
  • 55

2 Answers2

0

On iOS the forms destructor Destroy is only called when the user manually close the app (double-tap home button and swipe away). The OnDestroy event is called in TCommonCustomForm.BeforeDestruction, which is currently not called when you close the app on iOS.

Under normal use iOS freezes your app and eventually removes it from memory without any Destroy notifications. This means you must instead use the Application events to call code that you would normally call in the Destroy Events (like saving state of app, etc).

When you app enters background you have to behave like it was closed. From background state it might be removed from memory without notification.

Hans
  • 2,220
  • 13
  • 33
  • On iOS the forms OnDestroy events are only called when the user manually close the app (double-tap home button and swipe away) => I try but never see the onDestroy called ... –  Jul 31 '17 at 07:36
  • @jacky You are right, so I updated my answer. It doesn't however change the fact that on iOS you should **not** use `OnDestroy` at all because you don't know if it is called. – Hans Jul 31 '17 at 10:57
  • this is the question, does onDestroy will be ever used or not! I saw it use when the app crash at loading for example –  Jul 31 '17 at 11:08
  • @jacky Yes, it is the question and the question points in a wrong direction, which is what I try to correct. Since you cannot rely on the destructor being called on iOS, you must use the application events instead. – Hans Jul 31 '17 at 11:43
-1

I set a breakpoint which is not fired for me when I abort the app. I am using 10.2 Tokyo. It may be that iOS does not let your app close itself so you cannot exit gracefully.

Roy Woll
  • 312
  • 1
  • 4