Add and Remove containers

Just starting out? Need help? Post your questions and find answers here.
RobertRioja
User
User
Posts: 71
Joined: Thu May 02, 2019 3:57 am
Location: USA
Contact:

Add and Remove containers

Post by RobertRioja »

I have a question about gadgets that contain other gadgets, like the PanelGadget.

I use AddGadgetItem to add a new panel to a PanelGadget. Then I add other gadgets to it. At some point, I want to remove the panel by using RemoveGadgetItem. Do I have to first remove each of the gadgets added to this panel? Or does removing the panel automatically remove the contained gadgets?

I know that visually there is no need to remove the contained gadgets. But I want to know if that leaves behind unnecessary stuff.

Thank you,
Robert
User avatar
RSBasic
Moderator
Moderator
Posts: 1218
Joined: Thu Dec 31, 2009 11:05 pm
Location: Gernsbach (Germany)
Contact:

Re: Add and Remove containers

Post by RSBasic »

I tested it with WinSpy.exe. After the removal also the sub-gadgets of PureBasic will be removed.
According to the memory, the handles are also released.
Image
Image
RobertRioja
User
User
Posts: 71
Joined: Thu May 02, 2019 3:57 am
Location: USA
Contact:

Re: Add and Remove containers

Post by RobertRioja »

Thank you for your reply.

There is however a problem I noticed. If a subgadget has been bound to an event handling callback procedure which is shared with other subgadgets from another container (like a "Help" button that shows the same text from any panel), then you MUST unbind the subgadgets before removing their container. Otherwise, the callback may be triggered unexpectedly.

Maybe these are things that should be added to the PB documentation.

Robert
User avatar
kenmo
Addict
Addict
Posts: 1967
Joined: Tue Dec 23, 2003 3:54 am

Re: Add and Remove containers

Post by kenmo »

RobertRioja wrote:There is however a problem I noticed. If a subgadget has been bound to an event handling callback procedure which is shared with other subgadgets from another container (like a "Help" button that shows the same text from any panel), then you MUST unbind the subgadgets before removing their container. Otherwise, the callback may be triggered unexpectedly.
I think I've experienced this before too, although I never formally tested or reported it.

Maybe it should be a Bug Report or Feature Request to immediately unbind callbacks upon freeing.
Or, maybe it's already doing that, but there are already calls in the queue that happen right after the gadget is released? Hmm...
RobertRioja
User
User
Posts: 71
Joined: Thu May 02, 2019 3:57 am
Location: USA
Contact:

Re: Add and Remove containers

Post by RobertRioja »

I tested it and found that it is definitely a problem. Bogus events pop up. So you really should unbind before removing. I will post it as a bug.

Robert
Post Reply