#PB_Event_GadgetRelease

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
hallodri
Enthusiast
Enthusiast
Posts: 208
Joined: Tue Nov 08, 2005 7:59 am
Location: Germany
Contact:

#PB_Event_GadgetRelease

Post 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.
User avatar
STARGÅTE
Addict
Addict
Posts: 2227
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: #PB_Event_GadgetRelease

Post by STARGÅTE »

+1
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
User avatar
Bisonte
Addict
Addict
Posts: 1305
Joined: Tue Oct 09, 2007 2:15 am

Re: #PB_Event_GadgetRelease

Post by Bisonte »

It's really necessary :!:
PureBasic 6.21 (Windows x64) | Windows 11 Pro | AsRock B850 Steel Legend Wifi | R7 9800x3D | 64GB RAM | RTX 5080 | ThermaltakeView 270 TG ARGB | build by vannicom​​
English is not my native language... (I often use DeepL.)
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: #PB_Event_GadgetRelease

Post 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. :)
I may look like a mule, but I'm not a complete ass.
BorisTheOld
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Apr 24, 2012 5:08 pm
Location: Ontario, Canada

Re: #PB_Event_GadgetRelease

Post 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:

Code: Select all

Destroy(panelitem-object-name)
That's all that need be coded. No events. No messy housekeeping. :)
For ten years Caesar ruled with an iron hand, then with a wooden foot, and finally with a piece of string.
~ Spike Milligan
Post Reply