Page 1 of 1

#PB_Any Question ?

Posted: Mon Jan 03, 2022 12:29 am
by Gary.Maine
Hi All,

This is not an issue, just wondering why, if you compile and run the following code from the IDE, note if press Button_0 and then press Button_1 and look at the Dubug Results. Close the program and run it again, the results of Button_0 is not te same. Just wondering why?

Thanks

Code: Select all

Procedure OpenWindow_0(x = 0, y = 0, width = 600, height = 400)
  Window_0 = OpenWindow(#PB_Any, x, y, width, height, "", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget)
  Button_0 = ButtonGadget(#PB_Any, 240, 190, 100, 25, "Button_0", #PB_Button_Left)
  Button_1 = ButtonGadget(2, 240, 220, 100, 25, "Button_1", #PB_Button_Left)   ; <<<<<<<<<<<<<< NOTE, no #PB_Any "
EndProcedure

Procedure Window_0_Events(event)
  Select event
    Case #PB_Event_CloseWindow
      ProcedureReturn #False

    Case #PB_Event_Menu
      Select EventMenu()
      EndSelect

    Case #PB_Event_Gadget
      Select EventGadget()
      EndSelect
  EndSelect
  ProcedureReturn #True
EndProcedure

OpenWindow_0()

Repeat
  event = WaitWindowEvent()
  
   If EventGadget() <> 0
    Debug EventGadget() 
     Else
   EndIf 
     
Until Window_0_Events(event) = #False

End

Re: #PB_Any Question ?

Posted: Mon Jan 03, 2022 1:03 am
by StarBootics
Fred can confirm that but my guess about what #PB_Any force the gadget library to do is to generate a 64 bits UUID of some sort. That's probably why you get a different value each time you run your program.

Best regards
StarBootics

Re: #PB_Any Question ?

Posted: Mon Jan 03, 2022 1:16 am
by Gary.Maine
StarBootics wrote: Mon Jan 03, 2022 1:03 am Fred can confirm that but my guess about what #PB_Any force the gadget library to do is to generate a 64 bits UUID of some sort. That's probably why you get a different value each time you run your program.

Best regards
StarBootics

StarBootics,
Makes sence, Just seem it may take more processing at both sides? Just wondering....

Thanks,

Gary

Re: #PB_Any Question ?

Posted: Mon Jan 03, 2022 1:33 am
by Demivec
In my opinion, I think the current theory on the results you saw for Button_0 is that the gadget number returned when #PB_ANY is used corresponds to the memory address of the information stored by PureBasic for a gadget. This ensures each number is unique. In contrast, a user supplied gadget number is an index into an array of similar gadget information that is kept by PureBasic for each object type.

According to the theory I shared, the different values for Button_0 on subsequent for merely show that the memory location used to store the information were different. That isn't unusual.