Closing event

Var MesDia As New MessageDialog
Var MesDiaButton As MessageDialogButton

MesDia.Icon = MessageDialog.GraphicCaution

MesDia.ActionButton.Caption = "Save"
MesDia.CancelButton.Visible = True 

MesDia.AlternateActionButton.Visible = True
MesDia.AlternateActionButton.Caption = "Don't Save"

MesDia.Message = "Do you want to save changes to this document before closing?"

MesDia.Explanation = "If you don't save, your changes will be lost. "


MesDiaButton = MesDia.ShowModal
                       
Select Case MesDiaButton 
  
Case MesDia.ActionButton
  MainWindow.SaveDocument()
  
Case MesDia.AlternateActionButton
  // user pressed Don't Save
  
Case MesDia.CancelButton
  // user pressed Cancel
  
End Select

What is problem in this code?
This code is not saving data when save is click.
What can be the code for Don’t Save and cancel.

Please, share the code of this Method.

What can be the code for Don’t Save and cancel.
No code ?

add a break point there …
and look what happens there.
output the folderitem save path.

if self.NameFile = nil then
  SaveAsDocument()
  
else
  
  try
    var SaveFile As TextOutputStream
    SaveFile = TextOutputStream.Create(self.NameFile)
    SaveFile.Encoding = Encodings.UTF8
    
    // -------------- TITLE BOX ----------------
    
    SaveFile.Write(TitleBox_1.Text)
    SaveFile.Write("field_divider")
    
    SaveFile.Write(TitleBox_2.Text)
    SaveFile.Write("field_divider")
    
    SaveFile.Write(TitleBox_3.Text)
    SaveFile.Write("field_divider")
    
    // -------------- TEXT BOX ----------------
    
    SaveFile.Write(TextBox_1.Text)
    SaveFile.Write("field_divider")
    
    SaveFile.Write(TextBox_2.Text)
    SaveFile.Write("field_divider")
    
    SaveFile.Write(TextBox_3.Text)
    SaveFile.Write("field_divider")
    
    SaveFile.Close()
    
    self.Title="Note++ - "+self.NameFile.Name
    
  catch DisplayError as IOException
    MessageBox(DisplayError.Message)
    
  end try
end if

Does your app only support one window at a time? If not you are going to have a problem with MainWindow.SaveDocument, it should be Self.SaveDocument(), or even just SaveDocument(). Within the window you can refer to “this window” as Self.

You also should not put this in the Closing event. It should be in the CancelClose event. The job of the Close event is to tidy up as the window closes. For example freeing up any objects that may be required. In CancelClose you can return True in order to prevent the window from closing, which is what you are going to need for CancelButton.

As a general principal you should turn off ImplicitInstance and manage your windows. About the only time you should use it is if you are building an app that only every has one window. Outside of the class you can find the frontmost window via App.Window(0)