IsValidPBEvent?[Resolved]

Just starting out? Need help? Post your questions and find answers here.
Fred
Administrator
Administrator
Posts: 16623
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: IsValidPBEvent?

Post 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.
collectordave
Addict
Addict
Posts: 1309
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: IsValidPBEvent?

Post by collectordave »

Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
Fred
Administrator
Administrator
Posts: 16623
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: IsValidPBEvent?

Post 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.
User avatar
TI-994A
Addict
Addict
Posts: 2512
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: IsValidPBEvent?

Post 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.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
collectordave
Addict
Addict
Posts: 1309
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: IsValidPBEvent?

Post 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().
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
User avatar
TI-994A
Addict
Addict
Posts: 2512
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: IsValidPBEvent?

Post 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:
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
collectordave
Addict
Addict
Posts: 1309
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: IsValidPBEvent?

Post 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.
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
Little John
Addict
Addict
Posts: 4519
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: IsValidPBEvent?

Post 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.
collectordave
Addict
Addict
Posts: 1309
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: IsValidPBEvent?

Post 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
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
Little John
Addict
Addict
Posts: 4519
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: IsValidPBEvent?

Post 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).
mestnyi
Addict
Addict
Posts: 995
Joined: Mon Nov 25, 2013 6:41 am

Re: IsValidPBEvent?

Post 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
User avatar
BasicallyPure
Enthusiast
Enthusiast
Posts: 536
Joined: Thu Mar 24, 2011 12:40 am
Location: Iowa, USA

Re: IsValidPBEvent?

Post 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
BasicallyPure
Until you know everything you know nothing, all you have is what you believe.
mestnyi
Addict
Addict
Posts: 995
Joined: Mon Nov 25, 2013 6:41 am

Re: IsValidPBEvent?

Post 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
User avatar
kenmo
Addict
Addict
Posts: 1967
Joined: Tue Dec 23, 2003 3:54 am

Re: IsValidPBEvent?

Post 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.
User avatar
HeX0R
Addict
Addict
Posts: 979
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

Re: IsValidPBEvent?

Post 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?
Post Reply