Delphi在保存对话框上覆盖现有文件 [英] Delphi overwrite existing file on save dialog

查看:701
本文介绍了Delphi在保存对话框上覆盖现有文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用TSaveDialog组件从按钮点击保存文件。但是,我无法保存现有的文件名。一般情况下,当您要保存在Windows中的现有文件时,会弹出一个消息框,询问您是否确实要覆盖该文件。这不是TSaveDialog组件的情况,它会继续前进并写入文件而不要求。

I am using the TSaveDialog component to save a file from a button click. However, I am having trouble with saving on an existing file name. Generally, when you want to save over an existing file in Windows, a message box pops up asking you if you really want to overwrite the file. This is not the case with the TSaveDialog component and it will go ahead and write over the file without asking.

我希望有一个TSaveDialog功能或事件,我可以使用,但我没有看到任何看起来像处理这个。所以可能是我简单地没有找到正确的方法来使用。如果有事件,我可以使用

I was hoping there was a TSaveDialog function or event that I could use but I have not seen anything that looks like it handles this. So it could be that I simplely haven't found the correct method to use. If there is an event, I could use

if FileExists(saveDialog.FileName) then
  //and so forth

但事件TSaveDialog有OnCanClose,OnClose,OnFolderChange,OnIncludeItem,OnSelectionChange,OnShow,OnTypeChange ..

but the events TSaveDialog has are OnCanClose, OnClose, OnFolderChange, OnIncludeItem, OnSelectionChange, OnShow, OnTypeChange...

我的问题是,如何弹出消息框来询问用户是否要使用TSaveDialog组件覆盖现有文件。谢谢。

My question is, how do I pop up a message box to ask the user if they want to overwrite the existing file using the TSaveDialog component. Thanks.

推荐答案

使用 saveDialog.Options:= saveDialog.Options + [ofOverwritePrompt] ,然后执行对话框。那么它会询问用户是否要覆盖该文件。

Use saveDialog.Options := saveDialog.Options + [ofOverwritePrompt] before you execute the dialog. Then it will ask if the user wants to overwrite the file or not.

但是你知道TSaveDialog实际上并不保存文件, 对?它只显示标准的Windows文件保存对话框,然后返回用户选择的路径。您必须使用此路径手动保存文件,例如。 MyStringList.SaveToFile(saveDialog.FileName)

But you do know that the TSaveDialog does not actually save the file, right? It just displays the standard Windows File Save dialog, and then returns the path the user chose. You have to save the file manually using this path, e.g. MyStringList.SaveToFile(saveDialog.FileName).

这篇关于Delphi在保存对话框上覆盖现有文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆