Close(ok) Button

TWELVE

Active Member
Licensed User
Hello,

i've got a question regarding the close/ok button every device app does have in the upper right corner.

My App has two ways to exit out of it.One is through a button and the other one is by use of the menu.I do some cleanup before i really terminate the application.

This looks like this:


B4X:
Sub Button3_Click
' Quit Button
ExitApp
End Sub

...

Sub Menu5_Click
' Menu Quit
ExitApp
End Sub

...


Sub ExitApp
...
do some clean up
...
AppClose
End Sub


If the user pushes the close/ok button, the app just terminates without doing any of my cleanup tasks.
To have the cleanup also done in this case, i just added the following:

B4X:
Sub Form1_Close
ExitApp
End Sub

This does not work as i expected.I get some excpetion messages related to file access and some (for me ) unpredictable behavior ( infinite loop for instance).Maybe these exceptions have to do with the form1 closure.


- can someone explain, why these exceptions occur..? I ran through the code, but i cannot explain this behavior, even then if i take into account that my form is ( probably ) already closed by the OS..?

-Is there a chance to just catch the close/ok button event without having the OS close the form..?


cheers

TWELVE
 

Rioven

Active Member
Licensed User
Longtime User
Hi twelve,

Is it maybe the application was just minimized or just hide in backround when when closing the form?

ie. when using the formlib.dll library.
form1.New1("form1",B4PObject(1)) '1st form library to enable minimize button
form1.MinimizeBox=True 'X' or 'OK' press just hide in background


make form1.MinimizeBox=false to disable.
 
Last edited:

TWELVE

Active Member
Licensed User
AppClose closes the main form and therefore launches Sub Form1_Close which then calls AppClose again.

The simplest solution is to move your cleanup code into Sub Form1_Close.

This was exactly the issue.I didn't know that AppClose calls the Form1_Close Sub.Is that documented somewhere in the manual ? If so i didn't find it.

You can use Form.CancelClose to cancel the closing process.


How is the syntax then, do you have an example piece of code..?


The Basic4PPC help is very poor, often i do not understand how a certain instruction or parameter does work, sometimes i don't even understand what the instruction does.


@Rioven: no i do not use the fullscreen stuff from the formlib, yet.

kind regards


TWELVE
 

Rioven

Active Member
Licensed User
Longtime User
Hi TWELVE,
This works for me.

B4X:
Sub Form1_Close
If Msgbox("quit application?","",cMsgboxYesNo,cMsgboxQuestion)=cyes Then
DoSomeCleanUp 
AppClose
Else
form1.CancelClose
End If
End Sub

@Rioven: no i do not use the fullscreen stuff from the formlib, yet.
Not for fullscreen but for the 'x' or 'ok' button on top right of the form to give you an option just to hide in background or to terminate the application. Most applications does use the hiding in background.
 

cdeane

Member
I have full screen on my ppc App. But I get a double take with Msgbox.
I have to accepet Yes or No twice to get it to work.

B4X:
Sub ImageButtonExitForm1_Click
  Msgbox ("Do you want to quit?",, cMsgBoxYesNo)
    Form1.Close
 End Sub

Sub Form1_Close
     If Msgbox ("Do you want to quit?",, cMsgBoxYesNo) = cNo Then
          Form1.CancelClose
      
     End If
End Sub
 
Last edited:

cdeane

Member
So I asume there is no way to use this CancelClose in full screen format?
 

Standa

Member
Licensed User
Longtime User
Hi, try this:
B4X:
Sub ImageButtonExitForm1_Click
    Form1.Close
End Sub

Sub Form1_Close
     If Msgbox ("Do you want to quit?",, cMsgBoxYesNo) = cNo Then
          Form1.CancelClose   
     End If
End Sub
 
Top