It is currently Tue Apr 07, 2020 8:29 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 61 posts ]  Go to page Previous  1, 2, 3, 4, 5  Next
Author Message
 Post subject: Re: IsValidPBEvent?
PostPosted: Tue Nov 17, 2015 8:29 am 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 14018
Location: France
collectordave wrote:
Code:
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:
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: IsValidPBEvent?
PostPosted: Tue Nov 17, 2015 8:35 am 
Offline
Addict
Addict

Joined: Fri Aug 28, 2015 6:10 pm
Posts: 1076
Location: Portugal
Except as discussed here?

http://www.purebasic.fr/english/viewtopic.php?f=13&t=63778

_________________
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: IsValidPBEvent?
PostPosted: Tue Nov 17, 2015 8:45 am 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 14018
Location: France
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: IsValidPBEvent?
PostPosted: Tue Nov 17, 2015 8:59 am 
Offline
Addict
Addict
User avatar

Joined: Sat Feb 19, 2011 3:47 am
Posts: 2305
Location: Singapore
TI-994A wrote:
...would you recommend such an approach as efficient? Or even necessary?
collectordave wrote:
Code:
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!


Top
 Profile  
Reply with quote  
 Post subject: Re: IsValidPBEvent?
PostPosted: Tue Nov 17, 2015 9:10 am 
Offline
Addict
Addict

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


Top
 Profile  
Reply with quote  
 Post subject: Re: IsValidPBEvent?
PostPosted: Tue Nov 17, 2015 9:15 am 
Offline
Addict
Addict
User avatar

Joined: Sat Feb 19, 2011 3:47 am
Posts: 2305
Location: Singapore
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!


Top
 Profile  
Reply with quote  
 Post subject: Re: IsValidPBEvent?
PostPosted: Tue Nov 17, 2015 9:25 am 
Offline
Addict
Addict

Joined: Fri Aug 28, 2015 6:10 pm
Posts: 1076
Location: Portugal
This discussion shows that it is needed.

http://www.purebasic.fr/english/viewtopic.php?f=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.


Top
 Profile  
Reply with quote  
 Post subject: Re: IsValidPBEvent?
PostPosted: Tue Nov 17, 2015 10:12 am 
Offline
Addict
Addict

Joined: Thu Jun 07, 2007 3:25 pm
Posts: 3800
Location: Berlin, Germany
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/viewtopic.php?f=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.

_________________
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups


Top
 Profile  
Reply with quote  
 Post subject: Re: IsValidPBEvent?
PostPosted: Tue Nov 17, 2015 10:53 am 
Offline
Addict
Addict

Joined: Fri Aug 28, 2015 6:10 pm
Posts: 1076
Location: Portugal
Quote:
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: IsValidPBEvent?
PostPosted: Tue Nov 17, 2015 11:05 am 
Offline
Addict
Addict

Joined: Thu Jun 07, 2007 3:25 pm
Posts: 3800
Location: Berlin, Germany
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).

_________________
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups


Top
 Profile  
Reply with quote  
 Post subject: Re: IsValidPBEvent?
PostPosted: Tue Nov 17, 2015 4:20 pm 
Offline
Addict
Addict

Joined: Mon Nov 25, 2013 6:41 am
Posts: 811
Quote:
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:
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


Top
 Profile  
Reply with quote  
 Post subject: Re: IsValidPBEvent?
PostPosted: Wed Nov 18, 2015 5:15 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Thu Mar 24, 2011 12:40 am
Posts: 536
Location: Iowa, USA
@mestnyi

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

Take a look at this topic.viewtopic.php?f=3&t=64018

_________________
BasicallyPure
Until you know everything you know nothing, all you have is what you believe.


Top
 Profile  
Reply with quote  
 Post subject: Re: IsValidPBEvent?
PostPosted: Wed Nov 18, 2015 9:03 pm 
Offline
Addict
Addict

Joined: Mon Nov 25, 2013 6:41 am
Posts: 811
I agree it would be if it were not so. :)
Code:
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


Top
 Profile  
Reply with quote  
 Post subject: Re: IsValidPBEvent?
PostPosted: Wed Nov 18, 2015 9:40 pm 
Offline
Addict
Addict
User avatar

Joined: Tue Dec 23, 2003 3:54 am
Posts: 1769
Code:
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:
Quote:
After a WindowEvent() or WaitWindowEvent() function, use this function to determine on which window the event has occurred.

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


Top
 Profile  
Reply with quote  
 Post subject: Re: IsValidPBEvent?
PostPosted: Wed Nov 18, 2015 10:16 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon Sep 20, 2004 7:12 am
Posts: 545
Location: Hell
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?

_________________
Link dead?
Change h3x0r.ath.cx into hex0rs.coderbu.de and all will be fine.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 61 posts ]  Go to page Previous  1, 2, 3, 4, 5  Next

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 3 guests


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