Solved

File Exists on save?

Posted on 2000-04-17
10
271 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

760 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now