How to loose control in your own event?

I have a list of TPanels in the FMX application and I want to free the panel if I click on it.

To release them directly in the Onclick handler, this is not so because I get an access violation. And I do not want to use windowsmessages (it is recommended in How to release control inside my event handler? And Why is my program error when I delete a button in my OnClick handler? ), Because it is a firemonkey application, and I do not know how these messages work on Android and Mac.

Is there any other solution?

+4
source share
1 answer

Use myObject.Release :

Marks this TFmxObject for deferred deletion.

Direct actions in this method:

  • set Parent = nil
  • insert an object into the slow delete list

Delayed action:

  • free object from the list ( vPurgatory ).

Remember that this Free method (and the FreeAndNil procedure) does not delete the object itself on mobile platforms:

// under ARC, this method is not actually called, because the compiler translates // the call is a simple assignment of nil to an instance variable, which then calls _InstClear

+8
source

All Articles