Solved

File Exists on save?

Posted on 2000-04-17
10
275 Views
Last Modified: 2010-04-04
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 :)
0
Comment
Question by:fibdev
10 Comments
 
LVL 6

Expert Comment

by:Jaymol
ID: 2723514
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
 
LVL 2

Expert Comment

by:rene100
ID: 2723528
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
 
LVL 2

Expert Comment

by:rene100
ID: 2723531
sorry jaymol, didn't see your comment...;-)
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 3

Author Comment

by:fibdev
ID: 2723601
How do I keep the savedialog open if they say no?
0
 
LVL 15

Expert Comment

by:simonet
ID: 2723624
A much better/easier way is to use the TSaveFileDialog component, since it can handle that sorta thing automatically.

Alex
0
 
LVL 3

Author Comment

by:fibdev
ID: 2723641
I don't have TSaveFileDilog, I don't think ...

I use Delphi 5 Standard
0
 
LVL 3

Author Comment

by:fibdev
ID: 2723643
I have TReplaceDialog but since Delphi is new to me, I don't know how to use it :(
0
 
LVL 2

Expert Comment

by:NetoMan
ID: 2723743
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
 
LVL 4

Accepted Solution

by:
jeurk earned 50 total points
ID: 2723809
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
 
LVL 3

Author Comment

by:fibdev
ID: 2724652
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

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question