File Exists on save?

How do I showmessage to user if they are trying to save over an existing file?

<Filename> already exists, Do you wish to replace it?
          <Yes>    <No>


A full example please :)
LVL 3
fibdevAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
jeurkConnect With a Mentor Commented:
Hello,
they is nothing to do, just set the options ofOverwritePrompt to true :
ofOverwritePrompt      Generates a warning message if the user tries to select a file name that is already in use, asking whether to overwrite the existing file. (Use with TSaveDialog and TSavePictureDialog.)
That's all.
0
 
JaymolCommented:
If FileExists(FileName) then
  If MessageDlg(FileName+' exists.  Are you sure you wish to save?',
                mtConfirmation, [mbYes, mbNo], 0)=mrYes then begin
    ...
    Do Save Stuff
    ...
  end else begin
    ...
    Do stuff if not saving
   ...
  end;
0
 
rene100Commented:
var
Ant: integer;
begin
if FileExists(Filename) then
   begin
   Ant:=MessageDlg'File '+Filename+'    already exists. Do you wish to replace it?',mtConfirmation,[mbYes,mbNo],0);
if ant=mryes then
   begin    
   //overwrite
   end;
else
   begin  
   //don't overwrite
   end;
end;

regards
rene
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
rene100Commented:
sorry jaymol, didn't see your comment...;-)
0
 
fibdevAuthor Commented:
How do I keep the savedialog open if they say no?
0
 
simonetCommented:
A much better/easier way is to use the TSaveFileDialog component, since it can handle that sorta thing automatically.

Alex
0
 
fibdevAuthor Commented:
I don't have TSaveFileDilog, I don't think ...

I use Delphi 5 Standard
0
 
fibdevAuthor Commented:
I have TReplaceDialog but since Delphi is new to me, I don't know how to use it :(
0
 
NetoManCommented:
fibdev:

"...How do I keep the savedialog open if they say no?..."

are you trying to say that if they don't want to replace they have to save the file with other name ?

then just put what jaymol or rene write in a loop sentence like :

goingOut = FALSE;
repeat

 / * here routine to ask file name */

 If FileExists(FileName) then
   If MessageDlg(FileName+' exists.  Are you sure you wish to save?',
                mtConfirmation, [mbYes, mbNo], 0)=mrYes then begin
     ...
     /* Do Save Stuff */
     goingOut = TRUE;
     ...
   end;
until goingOut;

NetoMan :}
0
 
fibdevAuthor Commented:
Thank you everyone for your input but this is exactly the solution i was looking for.

Neto, everyone, I will remember your input If I ever want more control than this for saving files.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.