I'm having a problem when binding an event inside a module.
First of all I'd like to know if it is in general ok to have several bindEvents for the same event:
Code: Select all
BindEvent(#PB_Event_CloseWindow,@function_1(), 1)
BindEvent(#PB_Event_CloseWindow,@function_2(), 1)
If it it ok to do so, please have a look at the following code. There is a function called bindOnCloseEvent which will bind the module-internal function onCloseWindow_3() to the given window. So when the window gets closed all of the bound functions should be called.
If I bind the function via my module-function bindOnCloseEvent after I called the rest of the BindEvent-function, everything seems to be fine.
But if I call it first, my programm will crash and I'll get an 'invalid memory access'-Error on line 31 which is the EndProcedure-Statement of onCloseWindow_1().
Code: Select all
EnableExplicit
DeclareModule Test
Declare bindOnCloseEvent(win_nr.i)
EndDeclareModule
Module Test
Procedure onCloseWindow_3()
Debug "onCloseWindow_3 in Module called..."
EndProcedure
Procedure bindOnCloseEvent(win_nr.i)
BindEvent(#PB_Event_CloseWindow, @onCloseWindow_3(), win_nr)
EndProcedure
EndModule
#Win_NR = 1
#Win_NR_Main = 2
Procedure CloseApp()
End
EndProcedure
Procedure onCloseWindow_1()
CloseWindow(EventWindow())
EndProcedure
Procedure onCloseWindow_2()
Debug "onCloseWindow_2 was called"
EndProcedure
UseModule Test
OpenWindow(#Win_NR, 100, 100, 100, 100, "Close Me")
OpenWindow(#Win_NR_Main, 400, 100, 100, 100, "Main")
; PROBLEM IF CALLED HERE!
; bindOnCloseEvent(#Win_NR)
BindEvent(#PB_Event_CloseWindow, @onCloseWindow_1(), #Win_NR)
BindEvent(#PB_Event_CloseWindow, @onCloseWindow_2(), #Win_NR)
BindEvent(#PB_Event_CloseWindow, @CloseApp(), #Win_NR_Main)
; No Problem here
; bindOnCloseEvent(#Win_NR)
Repeat
WaitWindowEvent()
ForEver
Greetings
Fips