Deleting an FMXobject inside its event handler

前端 未结 1 585
梦毁少年i
梦毁少年i 2021-01-27 10:58

I have the following components, tncrdragdata (tframedscrollbox) tdragdata (tgroupbox)

The main Idea is to combine th

相关标签:
1条回答
  • 2021-01-27 11:22

    I found something interesting about FreeNotification() method here.

    Use FreeNotification to register AComponent as a component that should be notified when the component is about to be destroyed. It is only necessary to register components this way when they are in a different form or have a different owner. For example, if AComponent is in another form and uses the component to implement a property, it must call FreeNotification so that its Notification method is called when the component is destroyed.

    For components with the same owner, the Notification method is called automatically when an application explicitly frees the component. This notification is not sent out when components are freed implicitly, because the Owner is already being freed.

    And then when I removed the line

    a.FreeNotification(self);
    

    In the method (the first component)

    procedure Tncrdragdata.additem(Aname:string);
    

    And the problem was gone.

    I think the problem is that I was calling the FreeNotification() method with Tdragdata, not having a different owner. Clearly I was breaking a rule.

    Thanks to @victoria and @CraigYoung for their help.

    0 讨论(0)
提交回复
热议问题