Page 3 of 5

Re: IsValidPBEvent?

Posted: Tue Nov 17, 2015 8:29 am
by Fred
collectordave wrote:

Code: Select all

Repeat
  
  Event = WaitWindowEvent()
  
  Select Event
         
    Case #PB_Event_Gadget
      
      Select EventWindow() ;Select window. Just search form here
     
        Case frmMain
        
          Event_Handler(event)
        
        Case frmSearch
        
          SearchFrm::Ok = 0
          SearchFrm::Event_Handler(event)

          ;After Searchform events
          If SearchFrm::Ok = 1 ;User pressed the OK button
        
            CurrentRow.i = 1
            Criteria = SearchFrm::SearchString
            GetTotalRecords(Criteria)
            CheckRecords()
            If TotalRows > 0
              Displayrecord(CurrentRow)
            Else
              SetGadgetText(str_Record,"")
            EndIf
          EndIf
      
      EndSelect
 
  EndSelect
     
ForEver 
All would be fine? Of course I would have to copy this over and over again for each event I wish a window to respond to! The lines
It should be fine. Usually, you write it the other way around (which is the same at the end):

Code: Select all

Repeat
  
  Event = WaitWindowEvent()
  
  Select EventWindow() ;Select window. Just search form here
 
    Case frmMain
    
      Select Event 
        Case #PB_Event_Gadget
          Event_Handler(event)
      EndSelect
    
    Case frmSearch
      
      Select Event 
        Case #PB_Event_Gadget
          SearchFrm::Ok = 0
          SearchFrm::Event_Handler(event)
    
          ;After Searchform events
          If SearchFrm::Ok = 1 ;User pressed the OK button
        
            CurrentRow.i = 1
            Criteria = SearchFrm::SearchString
            GetTotalRecords(Criteria)
            CheckRecords()
            If TotalRows > 0
              Displayrecord(CurrentRow)
            Else
              SetGadgetText(str_Record,"")
            EndIf
          EndIf
      
      EndSelect
  EndSelect
     
ForEver
If you have any problem with this code, just post a small working snippet demonstrating it.

Re: IsValidPBEvent?

Posted: Tue Nov 17, 2015 8:35 am
by collectordave

Re: IsValidPBEvent?

Posted: Tue Nov 17, 2015 8:45 am
by Fred
Well your posted code is wrong, as you don't check for any specific events, but you don't seem to accept it, so I will stop trying to help here.

Re: IsValidPBEvent?

Posted: Tue Nov 17, 2015 8:59 am
by TI-994A
TI-994A wrote:...would you recommend such an approach as efficient? Or even necessary?
collectordave wrote:

Code: Select all

Procedure IsValidPBEvent(event)
  Select event
    Case  #PB_Event_Menu            ,
          #PB_Event_Gadget          ,
          #PB_Event_SysTray         ,
          #PB_Event_Timer           ,
          #PB_Event_CloseWindow     ,
          #PB_Event_Repaint         ,
          #PB_Event_SizeWindow      ,
          #PB_Event_MoveWindow      ,
          #PB_Event_MinimizeWindow  ,
          #PB_Event_MaximizeWindow  ,
          #PB_Event_RestoreWindow   ,
          #PB_Event_ActivateWindow  ,
          #PB_Event_DeactivateWindow,
          #PB_Event_WindowDrop      ,
          #PB_Event_GadgetDrop      ,
          #PB_Event_RightClick      ,
          #PB_Event_LeftClick       ,
          #PB_Event_LeftDoubleClick
      ProcedureReturn #True
    Default
      ProcedureReturn #False
  EndSelect ;event
EndProcedure
No, it's not needed. You have to respond to specific events, so even if EventWindow() isn't -1 for an OS event (which can be the case as PB sometimes maps PB event constant values with real OS event value for historical reasons) and you don't have it in your Select/Case, it won't be processed. So in both way, you can't have any issues.
Absolutely! Thanks for the concise explanation, Fred.

Re: IsValidPBEvent?

Posted: Tue Nov 17, 2015 9:10 am
by collectordave
Sorry but I do accept it. Once the event has been routed to the correct window i check for specific PB events.

The code also works fine.

No help required with this.

The issue is that EventWindow() returns the window number\ID of the last window on which a valid PB event happened even when non valid PB events happen. It does not return -1 for non valid PB events in every case. As stated elsewhere the return value of EventWindow() is only guaranteed after a valid PB event.

This procedure simply checks that a valid PB event has occurred and is used before routing the event to the correct window using EventWindow().

Re: IsValidPBEvent?

Posted: Tue Nov 17, 2015 9:15 am
by TI-994A
collectordave wrote:Sorry but I do accept it... This procedure simply checks that a valid PB event has occurred and is used before routing the event to the correct window using EventWindow().
But as Fred has clearly said, it's not needed. So, you're not accepting it. :lol:

Re: IsValidPBEvent?

Posted: Tue Nov 17, 2015 9:25 am
by collectordave
This discussion shows that it is needed.

http://www.purebasic.fr/english/viewtop ... 13&t=63778

The issue is that EventWindow() returns the window number\ID of the last window on which a valid PB event happened even when non valid PB events happen. It does not return -1 for non valid PB events in every case. As stated elsewhere the return value of EventWindow() is only guaranteed after a valid PB event.

Re: IsValidPBEvent?

Posted: Tue Nov 17, 2015 10:12 am
by Little John
Fred wrote:Well your posted code is wrong, as you don't check for any specific events, but you don't seem to accept it, so I will stop trying to help here.
collectordave wrote:This discussion shows that it is needed.

http://www.purebasic.fr/english/viewtop ... 13&t=63778
The issue is that EventWindow() returns [...]
The main issue in all the "event and eventwindow" discussions started here by you is, that you refuse to learn some simple basic rules how things are working in PureBasic. This has to be stated clearly, so that other newbies who'll read these threads won't get the wrong impression that PureBasic has got a problem in this regard.

Re: IsValidPBEvent?

Posted: Tue Nov 17, 2015 10:53 am
by collectordave
The main issue in all the "event and eventwindow" discussions started here by you is, that you refuse to learn some simple basic rules how things are working in PureBasic. This has to be stated clearly, so that other newbies who'll read these threads won't get the wrong impression that PureBasic has got a problem in this regard.
At no point have I even suggested that PB has a problem in this regard.

In fact I believe after my few months looking at Pb that it is a powerfull programming tool that outstrips VB except for all the control support VB has. i have learn't the rules.

A quick simple example.

I am told that i can enter the kitchen only when the door is open. So i check the door is open and if t is i enter the kitchen. i casn write this as.

If KitchenDoorOpen
enter kitchen
endif

Of course i can now change these around to

If IsValidPBEvent()
use eventwindow
endif

As i have been told that eventwindow() only returns a valid window number etc after a valid window event

Re: IsValidPBEvent?

Posted: Tue Nov 17, 2015 11:05 am
by Little John
collectordave wrote:At no point have I even suggested that PB has a problem in this regard.
:?: :?:
You are writing it all the time (e.g. just read your own text that I quoted in my previous message).

Re: IsValidPBEvent?

Posted: Tue Nov 17, 2015 4:20 pm
by mestnyi
EventWindow() can either return a valid window or -1, no any random value.
This is not true. Fred.
I how much time trying to explain it.
the same is the case with eventtype () and eventgadget ().

Code: Select all

Procedure Close()
  Debug "Close() "+EventWindow()
  PostEvent( #PB_Event_CloseWindow ) ; 0 why? there must be -1
EndProcedure

OpenWindow(10, 600, 200, 100, 205, "Event_0", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)

BindEvent(#PB_Event_CloseWindow, @Close(), 10)
Repeat
  If EventWindow() = 0
    Debug "0 why? there must be -1 "+EventWindow() ; 
  EndIf
  
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Debug "Event_CloseWindow "+EventWindow()
      
  EndSelect
ForEver

Re: IsValidPBEvent?

Posted: Wed Nov 18, 2015 5:15 pm
by BasicallyPure
@mestnyi

The problem here is with PostEvent() not EventWindow().

Take a look at this topic.http://www.purebasic.fr/english/viewtop ... =3&t=64018

Re: IsValidPBEvent?

Posted: Wed Nov 18, 2015 9:03 pm
by mestnyi
I agree it would be if it were not so. :)

Code: Select all

OpenWindow(10, 600, 200, 100, 205, "Event_0", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)

Repeat
  If EventWindow() = 0
    Debug "0 why? there must be -1 "+EventWindow() ; 
  EndIf
  
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Debug "Event_CloseWindow "+EventWindow()
      
  EndSelect
ForEver

Re: IsValidPBEvent?

Posted: Wed Nov 18, 2015 9:40 pm
by kenmo

Code: Select all

OpenWindow(10, 600, 200, 100, 205, "Event_0", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
Debug EventWindow() ;  0
Debug EventWindow() ;  0

WindowEvent()
Debug EventWindow() ; -1
Debug EventWindow() ; -1
From the help:
After a WindowEvent() or WaitWindowEvent() function, use this function to determine on which window the event has occurred.

Re: IsValidPBEvent?

Posted: Wed Nov 18, 2015 10:16 pm
by HeX0R
The good thing with coding is, anyone can do whatever he wants to.
If collectordave wants to use a totaly useless procedure ... no problem, just do it.

But isn't it strange, that no one of the other few thousand PB-users ever were in need of something like this?