Having started programming with PB I needed a way to reliably route messages to the correct message procedure for processing. Ran into some trouble using EventWindow(). After some lengthy discussion here it has been stated that EventWindow() is only valid after a valid PB event.
A good few examples of how to do this have been posted. Thanks to all. My way of overcoming this is to use the following procedure.
In short, totally unnecessary, redundant, and counter-productive.
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
When I am designing a new program I cannot predict how many windows I will have to open or what PB events I will need to process, this means that I cannot follow some of the advice given here and check each individual event in the event loop.before I cann EventWindow().
It also makes it possible for me to design a new window with all its functions and when happy to transform this into a module for inclusion in the main program.
It also frees up the main event\message loop to simple ensure that messages about events on any of the applications windows are routed to the correct Event\message procedure for processing.
As I have been told that EventWindow() is only guaranteed to return a correct window ID after a Valid PB event the simplest way is to check that a valid event has been returned before routing.
Sorry to hear you do not wish to register.
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.
collectordave wrote:It also frees up the main event\message loop to simple ensure that messages about events on any of the applications windows are routed to the correct Event\message procedure for processing.
I strongly recommend you to rethink your current code structure and event handling because just by looking at this procedure more experienced PB programmers can see that there is somethig wrong.
Better use BindEvent() instead. It automatically does all the "checking" and creates the cleanest event loop ever (if done correctly).
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
collectordave wrote:When I am designing a new program I cannot predict how many windows I will have to open or what PB events I will need to process...
Doesn't sound like much of a design to begin with.
But it explains a lot.
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
I strongly recommend you to rethink your current code structure and event handling because just by looking at this procedure more experienced PB programmers can see that there is somethig wrong.
Could the more experienced PB programmers explain what is wrong? Please?
Better use BindEvent() instead.
Will have a look at bind 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.
I simply want all valid PB events that happen on a window to be sent to that windows Event_Handler procedure.
BindEvent seems to deal with just a single event at a time.
Is there a way to use BindEvent to send all events that happen on a window to a set procedure?
From the help file it also looks like bind event only reacts correctly to valid PB events. Is this true? If so does it filter out all non valid PB events?
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.
collectordave wrote:I simply want all valid PB events that happen on a window to be sent to that windows Event_Handler procedure...
Time to take Schumacher's advice.
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
BindEvent seems to deal with just a single event at a time.
Is there a way to use BindEvent to send all events that happen on a window to a set procedure?
From the help file it also looks like bind event only reacts correctly to valid PB events. Is this true? If so does it filter out all non valid PB events?
Sorry expected an answer to my post.
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.
collectordave wrote:I simply want all valid PB events that happen on a window to be sent to that windows Event_Handler procedure. [...] Is there a way to use BindEvent to send all events that happen on a window to a set procedure?
Why? The whole point is to put all logic needed to react on one specific event in one event handling procedure.
In my opinion it's the preferred way of dealing with events as it encourages you to use the MVC pattern, automatically creates cleaner code (compared to the traditional select block) and is closer to the handling of other modern programming languages.
collectordave wrote:From the help file it also looks like bind event only reacts correctly to valid PB events. Is this true? If so does it filter out all non valid PB events?
Yes. But you can make it react on custom events too (meaning those you've triggered yourself with PostEvent()).
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
It is only my opinion but when I think of one specific event I think of, lets say a button click event, this button can be on one of several windows each of which can be called btnOk as a variable. It is sorting out which one was clicked and then the action to be taken that I need to get to. Routing events to a windows event procedure is to my mind keeping all the code in one event procedure as it will call the relevent procedure then return to the main loop. So the code to react to one specific event is in one sprcific code block and no other which may be the main window event handler or on another window.
If I first react to a button click event and then try to route the event to the correct procedure for that button I am still left with the traditional select..end select to route that event to the correct procedure. I find it easier to use eventwindow first and route the message directly to the particular windows event handler.
I have also found that it helps with debugging. As i create each window used in my application separately, as a module, and test separately when a bug appears I can easily convert that particular window module to a stand alone window and test. Leaves with two choices for each bug. Either the particular window is not reacting to the event correctly or the message is not being routed there correctly.
The last point is that I do not wish to react to any non valid PB events. This simple procedure roots them out immediatly and discards them so all windows in the application which recieve events from the main loop only get official\valid PB events.
Thanks for the link to MVC I will read that later.
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.
Hi collectordave
I think you can not use a variable for more than one object in the same thread
But next is how to handle more than one window in the same events block
It will not be easy
Good luck