B4J Question [solved]Is there an event fired when any form is closed by the windows [X] button

Hilton

Active Member
Licensed User
Longtime User
I would like to know if there is an event that fires when a form is being closed in a module. If not, can one be created using JO? I am not from the Java world so the JO seems a bit strange, but hopefully this can be the beginning of my familiarisation.

I see that _CloseRequest event works in Main but does not seem to work in code modules with forms.

Thanks - Hilton
 

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
Ey I am pretty sure it works on code modules. There is no reason for not to.

Check.
That form is dimmed in the same module
that the event name is equal in the initialization and the sub.
Use the events shorcut (write the word Sub + tab) to get the correct event.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Ey I am pretty sure it works on code modules. There is no reason for not to.
Sure. CodeModules does not have a Context. There can be no events in a Code module. This is reason enough. This is, at least, true in B4A
 
Upvote 0

mangojack

Well-Known Member
Licensed User
Longtime User
I would like to know if there is an event that fires when a form is being closed in a module.

As @Enrique Gonzalez R stated just make sure your Initialization name = EventName.

B4X:
Public Sub StartModule    'this is a sub I call start/show new form/module
    frmExpenses.Initialize("frmExpenses", 1280, 700)
    '.......................

Sub frmExpenses_CloseRequest (EventData As Event)
    EventData.Consume  'stop form from unloading
   
    'do some stuff first ...
    Log("Closing Form Now ...")
    frmExpenses.Close
End Sub


But note ... It appears this event will only fire if the form is closed via Form X click.

I have other forms that are closed via Image/Button with a call formName.Close and the Event does not fire.
 
Upvote 0

Hilton

Active Member
Licensed User
Longtime User
Thank you for your responses.

I have done as you folk suggested (checked the initialization stub). My code is similar to mj's, but only the module Main responds. I will set up a test app and try that just in case I am doing something else that is plain silly. I will let you know what happens.
Thanks - Hilton.
 
Upvote 0

Hilton

Active Member
Licensed User
Longtime User
Each afternoon at 3pm I play 9holes of golf, I enjoy the walk. Anyway, on the way there a light bulb switched on in my head - yes the problem is ME.

I have a class that implements my pattern of work and is the engine that modules implement, pass some parameters and then tell it to go. I simply put the code in the module instead of in the class which then informs the module which then cleans up.

Again, thank you for being keen to help.
Hilton.
 
Upvote 0

mangojack

Well-Known Member
Licensed User
Longtime User
Upvote 0
Top