B4J Code Snippet Save changes before closing with a resumable sub

Discussion in 'B4J Code Snippets' started by Erel, Apr 9, 2019.

  1. Erel

    Erel Administrator Staff Member Licensed User

    Code:
    Sub MainForm_CloseRequest (EventData As Event)
       EventData.Consume
       
    Dim sf As Object = xui.Msgbox2Async("Save changes?""Title""Yes""Cancel""No"Null)
       
    Wait For (sf) Msgbox_Result (Result As Int)
       
    If Result = xui.DialogResponse_Positive Then
           
    'save changes
       End If
       
    If Result <> xui.DialogResponse_Cancel Then
           MainForm.Close
       
    End If
    End Sub
    The code might be a bit confusing. Remember that from the calling method perspective, a call to Wait For or Sleep is equivalent to a call to Return.
    This means that we must consume the event before calling Wait For. Otherwise the form will be closed.

    If the user didn't click on cancel then we call Form.Close to close it. The CloseRequest event will not be fired in that case.
     
    Last edited: Apr 9, 2019
    Jorge M A, Harris, GMan and 3 others like this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice