Only change is the File Type Group (to save as a .sqlite file).
What is this “code” suposed to do?
Read the docs. And if you do not like how it comes, copy the code from the LR and paste it here to understand, as Alberto said.
@all:
No application do that. When you save a document in an already existing file, you are warned and asked if you want to overwrite the existing file. If yes, the old file is destroyed and replaced by a new; this is not the case.
There is no code to use to delete the file.
Try by your self with code to save a data base and try the sam with code to save text file:
Pseudo code to save as text file (*):
saveTOS = TextOutputStream.Save(saveFile)
saveTOS.Write “Text data”
saveTOS.Close
In this condition the previous contents is replaced.
How long are you using Xojo (and a computer) to not understand ?
(*) Real code exists in LR TextOutputStream entry.
the behavior of the dialog is
if you select a new file the dialog return the folderitem to use later
if you select a existing file the dialog show a warning, ok,ok return the folderitem else select other or cancel.
cancel return nil
if you overwrite the file or append your file then is your part.
its not the job of a file dialog to delete things.
That’s because all the other applications check for the existance of the file and delete it if it’s already there, or simply overwrite it. You’re a programmer. It’s up to you to delete the file if that’s what you desire. No dialog will actually delete the file in any application. It’s all done afterward before the new contents are written out.
The night was good and prolific. The day was long and in the evening I wrote:
//
// Global Property
// gSQLite_FI As FolderItem
//
Var Save_Dlg As New SaveFileDialog
// Set the SaveFileDialog properties
Save_Dlg.InitialFolder = SpecialFolder.Documents
Save_Dlg.PromptText = "Choose"
Save_Dlg.SuggestedFileName = "My_SQLite DB.sqlite"
Save_Dlg.Title = "Create a SQLite File"
Save_Dlg.Filter = FTG_SQL.sqlite
mSQLite.gSQLite_FI = Save_Dlg.ShowModal
If mSQLite.gSQLite_FI = Nil Then
// User canceled
Return
End If
// Delete the file if it is not empty
If mSQLite.gSQLite_FI.Length > 0 Then
mSQLite.gSQLite_FI.Delete
End If
Looks strange, never believe this have to be done n my 42 years in the computing industry, but this works for SQLite database saving.
Why the OS ask me if I want to replace the previous file is a mysery (Err, typo: mystery).
The OS asks if you want to replace the file as a courtesy in the dialog. If you say OK, then the dialog proceeds and returns the FolderItem. If you say Cancel, then the dialog continues to prompt for a file name and location. That is the function of the SaveFileDialog. The dialog itself is not going to delete the file. That would be potentially bad - suppose your app just wanted to append to it. It’s up to your app to decide what to do with the folderitem - delete, append, merge information, whatever. It has always been this way. I think if you review some of your old code, you will find that you were testing for Exists and deleting if needed.
You are still going to find all kind of problems comparing the Length of the file instead of if just exists or not and not having a check to see if you can actually delete the file. (It could be in use by another app)