有一個關於TSaveDialog和[ofOverwritePromt]的想法在Delphi overwrite existing file on save dialog的簡單問題。TSaveDialog文件擴展名和[ofOverwritePromt]問題
所以我的問題/場景如下:
- 我有一個
TSaveDialog
- 我設置
[ofOverwritePromt]
在Options
- 我設置了過濾器「PDF(* .PDF)| * .PDF 「
- 篩選指標被設定爲1
所以現在我執行程序並調用對話框。如果我的鼠標或鍵盤選擇(而無需鍵入)該文件存在,那麼保存對話框,詢問我的消息覆蓋:
但是,如果我做同樣的動作,但輸入類似「測試」的文件名,而不指定保存對話框沒有確認覆蓋的擴展名。 我知道實際上它會返回另一個文件名「C:\ Users \ xxx \ Desktop \ Test」而不是「C:\ Users \ xxx \ Desktop \ Test.pdf」。這是一種不是很好,如果對話框,要求您保存文件,但你需要鍵入擴展.. 所以平時我處理這樣的:
repeat
{ Ask for the file if not silent }
if not dlgSave.Execute then
Exit;
{ Read the filename from the save dialog }
LTempFile := dlgSave.FileName;
if not SameText(ExtractFileExt(LTempFile), '.pdf') then
begin
{ Add the extension }
LTempFile := LTempFile + '.pdf';
{ As we bypassed the overwrite check in dialog do it now }
if FileExists(LTempFile) then
if MsgWarn(Format('%s already exists. Replace?', [ExtractFileName(LTempFile)]), mbOKCancel) <> mrOk then
Continue;
end;
Break;
until False;
有沒有辦法做到這一點更優雅沒有自定義標準對話框?
非常感謝!我怎麼會錯過這個屬性......也許是因爲這是度假前的最後一天:D –
不客氣。如果你很高興,請將答案標記爲已接受。 – Dsm