How to free a control in its own event?

谁说我不能喝 提交于 2019-12-10 16:37:52

问题


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

To free them directly in the Onclick-handler is not the right way, because I get an access-violation. And I don't want to use windowsmessages (recommended in How to free control inside its event handler? and Why does my program crash when I destroy a button in its own OnClick handler?) because it is a firemonkey application and I do not know how these messages work on android and mac.

Is there another solution?


回答1:


Use myObject.Release:

Marks this TFmxObject object for delayed deletion.

Immediate actions in this method:

  • set Parent = nil
  • insert object into delayed delete list

Delayed action:

  • free object from list (vPurgatory).

Remember, that method Free (and procedure FreeAndNil) does not remove the object itself in mobile platforms:

// under ARC, this method isn't actually called since the compiler translates // the call to be a mere nil assignment to the instance variable, which then calls _InstClear



来源:https://stackoverflow.com/questions/31785692/how-to-free-a-control-in-its-own-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!