Sorry, but While WindowEvent() isn't allowed in
an 'binded' Procedure. This throws an error.
No error thrown on my machine. However there is no need for the windowevent bits in the setsometext procedure. the problem is the timeconsumingcode. If the procedure does not allow time for things to happen then they will not happen. must also be carefull with Delay(1000) as that halts programme execution, so nothing happens.
Secondly I am not using a button to start a
text output. Text is generated depending on
some results in that "time consuming procedure"
and are to be displayed, sometimes the text
area has to be cleared.
I have modyfied the code as per the above. You can still set the text by pressing the return key but text is also set by the time consuming code. I know there is a "While WindowEvent() : Wend" loop in the time consuming code, this is to allow the OS time to update everything. if you do not have that somewhere in your timeconsuming code then you need to find some other way of returning to the main event loop of your programme either by doing the time consuming code in a thread as shown above or by breaking down your timeconsuming code into smaller blocks. The button is only there so you can keep checking.
Remember while your code is running, and not picking up events from your queue with waitwindow event or windowevent then the OS will eventually tell the user that your application has crashed with the (Not Responding) message. Bindevent does not clear the event queue so cannot be used for that purpose as all the other events will still build up until your queue is full.
Code: Select all
Global Text.s
Procedure SetSomeText()
Static x
Debug x
Select x
Case 0
ClearGadgetItems(2)
Text = ""
Case 1
For i=1 To 25
Text = Text +"11111111111111111111111111111111"+#CRLF$
Next
SetGadgetText(2, Text)
Text = ""
Case 2
For i=1 To 25
Text = Text +"22222222222222222222222222222222"+#CRLF$
Next
SetGadgetText(2, Text)
text = ""
EndSelect
x = x + 1
If x > 2
x = 0
EndIf
EndProcedure
Procedure TimeConsumingCode()
For i=1 To 5000000
Select i
Case 1000000
text = "Just testing after first 1000000"
SetGadgetText(2, Text)
Case 2000000
SetSomeText()
Case 3000000
SetSomeText()
Case 4000000
SetSomeText()
EndSelect
While WindowEvent() : Wend
y=Pow(2, i)
Next
Debug "Time Consuming Code Finished"
EndProcedure
OpenWindow(1, 10, 10, 640, 480, "")
ButtonGadget(1, 5, 5, 100, 20, "")
EditorGadget(2, 5, 30, 630, 445, #PB_Editor_WordWrap)
AddKeyboardShortcut(1, #PB_Shortcut_Return, 10)
BindEvent(#PB_Event_Menu, @SetSomeText(), 1)
Quit=#False
Text = ""
TimeConsumingCode()
Repeat
Event=WaitWindowEvent()
Select Event
Case #PB_Event_CloseWindow
Quit=#True
Case #PB_Event_Gadget
Select EventGadget()
Case 1
Debug "Time Consuming Code Started"
TimeConsumingCode()
EndSelect
EndSelect
Until Quit=#True
All you need to do is run the programme and the text will be set from the time consuming code.
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.