It is currently Sun Feb 16, 2020 9:00 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Bind and unbind gadgets
PostPosted: Mon Jun 17, 2019 5:50 pm 
Offline
User
User

Joined: Thu May 02, 2019 3:57 am
Posts: 46
Location: USA
I found what appears to be a bug, or at least an oversight.

Please check this post:

viewtopic.php?f=13&t=73037


Top
 Profile  
Reply with quote  
 Post subject: Re: Bind and unbind gadgets
PostPosted: Mon Jun 17, 2019 8:00 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3508
I do not think it is a bug or oversight
BindGadgetEvent() - UnbindGadgetEvent()
AddWindowTimer() - RemoveWindowTimer()
AddKeyboardShortcut() - RemoveKeyboardShortcut()

And so on it is the Programmer taking care issue
You want to free the gadget ,you unbind the gadget event first if there is any then free the gadget

_________________
Egypt my love


Top
 Profile  
Reply with quote  
 Post subject: Re: Bind and unbind gadgets
PostPosted: Mon Jun 17, 2019 8:34 pm 
Offline
User
User

Joined: Thu May 02, 2019 3:57 am
Posts: 46
Location: USA
Yes, Rashad, I understand and agree. But there is the perception that you can remove a container gadget without removing the individual subgadgets first. Therefore, it follows that unbinding would be also automatically done.

If unbinding has to be done first anyway, it would be good to note this in the PB documentation, so there are no misunderstandings.

But I really think that removing a gadget, either directly or by removing its container, should also remove its bindings, if any.

Robert


Top
 Profile  
Reply with quote  
 Post subject: Re: Bind and unbind gadgets
PostPosted: Mon Jun 17, 2019 9:19 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3508
I respect your point of view but I can not agree
It will be a mess
We have IsGadget() ,IsWindow() etc for that
Next you can free then create again with no problem
Code:
Procedure do()
  If IsGadget(1)
    Debug "OK"
  EndIf
EndProcedure
 
LoadImage(0, #PB_Compiler_Home+"Examples\Sources\Data\File.bmp")
LoadFont(0,"Arial",12)
OpenWindow(0, 0, 0, 640, 340, "ListIconGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ButtonGadget(1,10,300,60,24,"Test #1")
ButtonGadget(2,80,300,60,24,"Test #2")
BindGadgetEvent(1,@do())
Repeat
  Select WaitWindowEvent() 
    Case #PB_Event_CloseWindow
      Quit = 1
           
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 1
        Case 2
          FreeGadget(1)
          Delay(200)
          ButtonGadget(1,10,10,60,24,"Test #1")

     EndSelect
  EndSelect
Until Quit = 1

_________________
Egypt my love


Top
 Profile  
Reply with quote  
 Post subject: Re: Bind and unbind gadgets
PostPosted: Mon Jun 17, 2019 10:05 pm 
Offline
Addict
Addict
User avatar

Joined: Tue Dec 23, 2003 3:54 am
Posts: 1730
1. I agree with Robert's request... it is normal PureBasic behavior for this kind of thing to be auto-released.

2. PB internals have access to the (linked list?) of binded callbacks... we don't have direct access to this, so it's easier for PB to unbind them all than us.

3. RASHAD, AddWindowTimer() is a bad counter-argument... because the help says "A timer is always attached to a window and will be removed if that window is closed." <-- That's what Robert is asking for

4. Also, RASHAD, your example code shows exactly the problem... you can create a new gadget with a reused ID (could be unrelated gadget, could be different gadget type) and still it's linked to an old callback! That's not safe!

5. Let's call it a Feature Request instead of a Bug Report :)

_________________
On GitHub: PB Includes - IDE Tools - Color Themes


Top
 Profile  
Reply with quote  
 Post subject: Re: Bind and unbind gadgets
PostPosted: Mon Jun 17, 2019 10:23 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3508
@kenmo
You did not understand what I meant
I do not think that there is a language designed to look after your mistakes(No crash) or we all will use it
If there is one please point me to use it
You are responsible for your code
I can agree if there is no Unbind() or checking for the absence of the object or ....or ...
Sorry no more argue I stop here :wink:

_________________
Egypt my love


Top
 Profile  
Reply with quote  
 Post subject: Re: Bind and unbind gadgets
PostPosted: Fri Jun 21, 2019 1:41 pm 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 13891
Location: France
Yes, it should be released automatically, I will take a closer look.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye