Page 1 of 1

Can I use #PB_Ignore for 'empty' PostEvent Parameters?

Posted: Sat Oct 03, 2020 1:59 pm
by Kurzer
I want to fire an event with PostEvent.

Code: Select all

PostEvent(Event [, Window, Object [, Type [, Data]])
A data value is to be passed (last parameter), but no window, no object and no EventType.

Can I use #PB_Ignore for this?

Code: Select all

PostEvent(#MyCustomEvent, #PB_Ignore, #PB_Ignore, #PB_Ignore, 300)
Or does it make no difference at all, because PureBasic doesn't care about these values at all? The event should be sent to all windows and I don't want that it is not sent to all windows by specifying a wrong constant at the parameter Window, Object and Type.

Markus

Re: Can I use #PB_Ignore for 'empty' PostEvent Parameters?

Posted: Sat Oct 03, 2020 2:13 pm
by mk-soft
Yes ;)
You can use all parameters as long as you structure your evaluation of the WaitWindowEvent correctly.
That means, always first evaluate the event (e.g. #PB_Event_CloseWindow) and then the meant window (EventWindow).

Code: Select all

;-TOP

Enumeration #PB_Event_FirstCustomValue
  #MyEvent_Data
EndEnumeration

Enumeration Windows
  #Main
EndEnumeration

Enumeration Gadgets
  
EndEnumeration

Enumeration Status
  #MainStatusBar
EndEnumeration

Procedure Main()
  
  #MainStyle = #PB_Window_SystemMenu | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget
  
  If OpenWindow(#Main, #PB_Ignore, #PB_Ignore, 800, 600, "Window" , #MainStyle)
    
    Debug "Constant #PB_Ignore = " + #PB_Ignore
    
    PostEvent(#MyEvent_Data, #PB_Ignore, #PB_Ignore, #PB_Ignore, 300)
    
    Repeat
      Select WaitWindowEvent()
        Case #PB_Event_CloseWindow
          Break
          
        Case #MyEvent_Data
          Debug "Window = " + EventWindow()
          Debug "Gadget = " + EventGadget()
          Debug "Type   = " + EventType()
          Debug "Data   = " + EventData()
          
      EndSelect
    ForEver
    
  EndIf
  
EndProcedure : Main()

Re: Can I use #PB_Ignore for 'empty' PostEvent Parameters?

Posted: Sat Oct 03, 2020 2:17 pm
by Kurzer
Great, many thanks, mk-soft.
You put a lot of effort and wrote an example. Image

Re: Can I use #PB_Ignore for 'empty' PostEvent Parameters?

Posted: Sat Oct 03, 2020 2:24 pm
by mk-soft
The PostEvent function does not trigger any internal actions. It only adds the message in the event buffer, which you then evaluate after WaitWindowEvent.

Re: Can I use #PB_Ignore for 'empty' PostEvent Parameters?

Posted: Sat Oct 03, 2020 3:06 pm
by mk-soft
Here is the proof how PostEvent works and the truth about the function EventTimer :wink:

Code: Select all

;-TOP

Enumeration #PB_Event_FirstCustomValue
  #MyEvent_Data
EndEnumeration

Enumeration Windows
  #Main
EndEnumeration

Enumeration Gadgets
  
EndEnumeration

Enumeration Status
  #MainStatusBar
EndEnumeration

Procedure Main()
  
  #MainStyle = #PB_Window_SystemMenu | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget
  
  If OpenWindow(#Main, #PB_Ignore, #PB_Ignore, 800, 600, "Window" , #MainStyle)
    
    Debug "Constant #PB_Ignore = " + #PB_Ignore
    Debug "----------------------------------"
    
    PostEvent(#MyEvent_Data, #PB_Ignore, #PB_Ignore, #PB_Ignore, 300)
    
    PostEvent(#PB_Event_Gadget, 1, 10, 100, 1000)
    
    AddWindowTimer(#Main, 999, 1000)
    
    Repeat
      Select WaitWindowEvent()
        Case #PB_Event_CloseWindow
          Break
          
        Case #PB_Event_Gadget
          Debug "#PB_Event_Gadget"
          Debug "Window          = " + EventWindow()
          Debug "Gadget (Object) = " + EventGadget()
          Debug "Type            = " + EventType()
          Debug "Data            = " + EventData()
          Debug "Timer  (Object) = " + EventTimer()
          Debug "----------------------------------"
          
        Case #PB_Event_Timer
          Debug "#PB_Event_Timer"
          Debug "Window          = " + EventWindow()
          Debug "Gadget (Object) = " + EventGadget()
          Debug "Type            = " + EventType()
          Debug "Data            = " + EventData()
          Debug "Timer  (Object) = " + EventTimer()
          Debug "----------------------------------"
          RemoveWindowTimer(#Main, 999)
          
        Case #MyEvent_Data
          Debug "#MyEvent_Data"
          Debug "Window          = " + EventWindow()
          Debug "Gadget (Object) = " + EventGadget()
          Debug "Type            = " + EventType()
          Debug "Data            = " + EventData()
          Debug "Timer  (Object) = " + EventTimer()
          Debug "----------------------------------"
          
      EndSelect
    ForEver
    
  EndIf
  
EndProcedure : Main()