WindowEvent() and WaitWindowEvent() can not be called from a 'binded' event callback

Just starting out? Need help? Post your questions and find answers here.
hdt888
User
User
Posts: 57
Joined: Sun Jul 07, 2024 8:42 am

WindowEvent() and WaitWindowEvent() can not be called from a 'binded' event callback

Post 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 ?
PB 5.x + 6.x + Win10. Feel the ...Pure... Power.
AZJIO
Addict
Addict
Posts: 2225
Joined: Sun May 14, 2017 1:48 am

Re: WindowEvent() and WaitWindowEvent() can not be called from a 'binded' event callback

Post 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.
infratec
Always Here
Always Here
Posts: 7662
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: WindowEvent() and WaitWindowEvent() can not be called from a 'binded' event callback

Post by infratec »

Youre ONE event loop is wrong.
User avatar
mk-soft
Always Here
Always Here
Posts: 6320
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: WindowEvent() and WaitWindowEvent() can not be called from a 'binded' event callback

Post 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.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
boddhi
Enthusiast
Enthusiast
Posts: 524
Joined: Mon Nov 15, 2010 9:53 pm

Re: WindowEvent() and WaitWindowEvent() can not be called from a 'binded' event callback

Post 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 :mrgreen: ), 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.
If my English syntax and lexicon are incorrect, please bear with Google translate and DeepL. They rarely agree with each other!
Except on this sentence...
Axolotl
Addict
Addict
Posts: 872
Joined: Wed Dec 31, 2008 3:36 pm

Re: WindowEvent() and WaitWindowEvent() can not be called from a 'binded' event callback

Post 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. :mrgreen:
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
User avatar
jacdelad
Addict
Addict
Posts: 2032
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: WindowEvent() and WaitWindowEvent() can not be called from a 'binded' event callback

Post 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.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
User avatar
mk-soft
Always Here
Always Here
Posts: 6320
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: WindowEvent() and WaitWindowEvent() can not be called from a 'binded' event callback

Post 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 :mrgreen: ), 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.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
boddhi
Enthusiast
Enthusiast
Posts: 524
Joined: Mon Nov 15, 2010 9:53 pm

Re: WindowEvent() and WaitWindowEvent() can not be called from a 'binded' event callback

Post by boddhi »

Axolotl wrote: P.S.: Most likely another question where the questioner shows no reaction to our answers. :mrgreen:
Give him the benefit of the doubt. Especially since not everyone's time zone is the same. :wink:
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. :D
If my English syntax and lexicon are incorrect, please bear with Google translate and DeepL. They rarely agree with each other!
Except on this sentence...
boddhi
Enthusiast
Enthusiast
Posts: 524
Joined: Mon Nov 15, 2010 9:53 pm

Re: WindowEvent() and WaitWindowEvent() can not be called from a 'binded' event callback

Post 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 :wink:

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! :mrgreen: ). :wink: :D
If my English syntax and lexicon are incorrect, please bear with Google translate and DeepL. They rarely agree with each other!
Except on this sentence...
Axolotl
Addict
Addict
Posts: 872
Joined: Wed Dec 31, 2008 3:36 pm

Re: WindowEvent() and WaitWindowEvent() can not be called from a 'binded' event callback

Post 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. :mrgreen:
Give him the benefit of the doubt. Especially since not everyone's time zone is the same. :wink:
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. :D
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. :oops:
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
User avatar
spikey
Enthusiast
Enthusiast
Posts: 778
Joined: Wed Sep 22, 2010 1:17 pm
Location: United Kingdom

Re: WindowEvent() and WaitWindowEvent() can not be called from a 'binded' event callback

Post 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
hdt888
User
User
Posts: 57
Joined: Sun Jul 07, 2024 8:42 am

Re: WindowEvent() and WaitWindowEvent() can not be called from a 'binded' event callback

Post 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.
PB 5.x + 6.x + Win10. Feel the ...Pure... Power.
Post Reply