Page 1 of 1
WindowEvent() and WaitWindowEvent() can not be called from a 'binded' event callback
Posted: Thu Jul 18, 2024 3:56 am
by hdt888
I call a child-form by clicking the checkbox in the parent-form. Child-form i also set a repeat to handle gadgets belonging to it.
i get the error:
WindowEvent() and WaitWindowEvent() can not be called from a 'binded' event callback
when i call show child-form.
What's the problem ?
Re: WindowEvent() and WaitWindowEvent() can not be called from a 'binded' event callback
Posted: Thu Jul 18, 2024 5:30 am
by AZJIO
Can you do a simplified example of how you do this? I'm sure that as long as you make an example, the problem will solve itself.
Re: WindowEvent() and WaitWindowEvent() can not be called from a 'binded' event callback
Posted: Thu Jul 18, 2024 7:09 am
by infratec
Youre ONE event loop is wrong.
Re: WindowEvent() and WaitWindowEvent() can not be called from a 'binded' event callback
Posted: Thu Jul 18, 2024 8:02 am
by mk-soft
There can only ever be one EventLoop with WaitWindowEvent() in the program.
WindowEvent() is only required for OpenWindowedScreen() to process all events in the screen loop.
Re: WindowEvent() and WaitWindowEvent() can not be called from a 'binded' event callback
Posted: Thu Jul 18, 2024 12:10 pm
by boddhi
Hello mk-soft,
mk-soft wrote:
There can only ever be one EventLoop with WaitWindowEvent() in the program.
Sorry, I know your great talent (which I can't compete with

), but I don't quite agree with you.
In theory, it's preferable, but it is possible to have several event management loops in the same program.
I have a program whose main window contains a lot of gadgets. These gadgets open a multitude of other modal windows via a single procedure and, for the sake of code readability, all the gadgets in these windows are managed by another event loop.
Re: WindowEvent() and WaitWindowEvent() can not be called from a 'binded' event callback
Posted: Thu Jul 18, 2024 1:48 pm
by Axolotl
I am pretty sure this is a general design thing (as always with this kind of questions).
But without any (compilable) code, we can only guess here.
P.S.: Most likely another question where the questioner shows no reaction to our answers.

Re: WindowEvent() and WaitWindowEvent() can not be called from a 'binded' event callback
Posted: Thu Jul 18, 2024 3:35 pm
by jacdelad
Using WaitWindowEvent() within a procedure bound with BindEvent is forbidden because said WaitWindowEvent() could call a bound event which leads to another WaitWindowEvent() which calls a bound function...and so on.
Use PostEvent() to communicate between the event loop and other functions. You can use PostEvent() within the bound function.
Re: WindowEvent() and WaitWindowEvent() can not be called from a 'binded' event callback
Posted: Thu Jul 18, 2024 4:22 pm
by mk-soft
boddhi wrote: Thu Jul 18, 2024 12:10 pm
Hello mk-soft,
mk-soft wrote:
There can only ever be one EventLoop with WaitWindowEvent() in the program.
Sorry, I know your great talent (which I can't compete with

), but I don't quite agree with you.
In theory, it's preferable, but it is possible to have several event management loops in the same program.
I have a program whose main window contains a lot of gadgets. These gadgets open a multitude of other modal windows via a single procedure and, for the sake of code readability, all the gadgets in these windows are managed by another event loop.
I remain of the opinion that there may only be one call of WaitWindowEvent() in the event loop in the programme. Unless you have a new window with its own event loop and no longer want to process the events from another window.
Re: WindowEvent() and WaitWindowEvent() can not be called from a 'binded' event callback
Posted: Thu Jul 18, 2024 4:44 pm
by boddhi
Axolotl wrote:
P.S.: Most likely another question where the questioner shows no reaction to our answers.
Give him the benefit of the doubt. Especially since not everyone's time zone is the same.
Sometimes I've asked a question and not been able to return to the forums for a few days due to unforeseen circumstances or other priorities.
Or more often the time to digest the code(s) given to me and come back to comment on it.

Re: WindowEvent() and WaitWindowEvent() can not be called from a 'binded' event callback
Posted: Thu Jul 18, 2024 4:57 pm
by boddhi
mk-soft wrote:
I remain of the opinion that there may only be one call of WaitWindowEvent() in the event loop in the programme.
We are agree
Your first post just missed a little nuance or precision (sometimes it's important for newbies in a domain. And on this subject, believe me, I know what I'm talking about!

).

Re: WindowEvent() and WaitWindowEvent() can not be called from a 'binded' event callback
Posted: Thu Jul 18, 2024 5:04 pm
by Axolotl
boddhi wrote: Thu Jul 18, 2024 4:44 pm
Axolotl wrote:
P.S.: Most likely another question where the questioner shows no reaction to our answers.
Give him the benefit of the doubt. Especially since not everyone's time zone is the same.
Sometimes I've asked a question and not been able to return to the forums for a few days due to unforeseen circumstances or other priorities.
Or more often the time to digest the code(s) given to me and come back to comment on it.
I know and I am patient and (hopefully) always willing to help, but when I look at his posting history I see a pattern. Just an observation, not a criticism.

Re: WindowEvent() and WaitWindowEvent() can not be called from a 'binded' event callback
Posted: Thu Jul 18, 2024 10:36 pm
by spikey
hdt888 wrote: Thu Jul 18, 2024 3:56 am
What's the problem ?
This error occurs when you do something like this, it's not supported:
Code: Select all
Global LastEvent
Procedure OnGadgetEvent()
LastEvent = WindowEvent()
Debug "An event!"
EndProcedure
OpenWindow(0, 100, 100, 200, 200, "Test", #PB_Window_SizeGadget | #PB_Window_SystemMenu)
EditorGadget(0, 10, 10, 180, 180)
BindEvent(#PB_Event_Gadget, @OnGadgetEvent(), #PB_All)
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
You can use
Event() inside an bound event procedure like this:
Code: Select all
Global LastEvent
Procedure OnGadgetEvent()
LastEvent = Event()
Debug "An event!"
EndProcedure
OpenWindow(0, 100, 100, 200, 200, "Test", #PB_Window_SizeGadget | #PB_Window_SystemMenu)
EditorGadget(0, 10, 10, 180, 180)
BindEvent(#PB_Event_Gadget, @OnGadgetEvent(), #PB_All)
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
Re: WindowEvent() and WaitWindowEvent() can not be called from a 'binded' event callback
Posted: Fri Jul 19, 2024 12:33 am
by hdt888
Thank you for all your help.
Thanks @spikey.
Because my code is quite long and I want to maintain privacy, I did not include the code in the post.
I was able to fix the error in my code myself.
The keyword here is the Event() function.