Page 1 of 1
#PB_Event_GadgetRelease
Posted: Wed Jun 26, 2013 4:12 pm
by hallodri
Hey Fred, please add a event for freeing gadgets.
Very useful for the canvas gadget, platform independent and custom gadgets are independent of the event loop.
Code: Select all
Procedure MyFreeGadget()
[...]
free(gadgetmem)
EndProcedure
Procedure MyGadget()
gadgetmem = Alloc(size)
gadget = CanvasGadget([...])
BindEvent(#PB_Event_GadgetRelease, gadget, @MyFreeGadget())
[...]
ProcedureReturn gadget
EndProcedure
FreeGadget (FreeGadgets) call the MyFreeGadget func.
Re: #PB_Event_GadgetRelease
Posted: Fri Jan 10, 2014 11:54 am
by STARGĂ…TE
+1
Re: #PB_Event_GadgetRelease
Posted: Fri Jan 10, 2014 5:46 pm
by Bisonte
It's really necessary

Re: #PB_Event_GadgetRelease
Posted: Fri Jan 10, 2014 6:12 pm
by srod
Most custom controls would perhaps be best served by offering up a FreeControl() or DestroyControl() type function which would perform all necessary house keeping before issuing a FreeGadget() call itself. In this way, there would be no need for a new event-type.
However, I can see why some would like it in order to safe guard against those apps which might simply close the parent window expecting all controls and associated memory etc. to be automatically freed etc.
Swings and roundabouts. I prefer to create simple OOP classes which then places the emphasis on the app developer to issue the relevant \Destroy() method calls etc. to explicitly delete the control. Makes for tighter code inmo.

Re: #PB_Event_GadgetRelease
Posted: Sat Jan 11, 2014 5:23 am
by BorisTheOld
srod wrote:I prefer to create simple OOP classes which then places the emphasis on the app developer to issue the relevant \Destroy() method calls etc. to explicitly delete the control. Makes for tighter code inmo.

Same here!
Except for a few lines of mainline code, our applications exist as a hierarchy of PB classes. Each object tracks the child objects attached to it, and the housekeeping is handled automatically within the individual classes.
As you say, the application code is a lot tighter, and it's certainly a lot easier to write and maintain.
For example, here's the code for destroying a PanelItem and all its associated gadgets, files, reports, etc:
That's all that need be coded. No events. No messy housekeeping.
