fibdev
asked on
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 :)
<Filename> already exists, Do you wish to replace it?
<Yes> <No>
A full example please :)
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
Ant: integer;
begin
if FileExists(Filename) then
begin
Ant:=MessageDlg'File '+Filename+' already exists. Do you wish to replace it?',mtConfirmation,[mbYes
if ant=mryes then
begin
//overwrite
end;
else
begin
//don't overwrite
end;
end;
regards
rene
sorry jaymol, didn't see your comment...;-)
ASKER
How do I keep the savedialog open if they say no?
A much better/easier way is to use the TSaveFileDialog component, since it can handle that sorta thing automatically.
Alex
Alex
ASKER
I don't have TSaveFileDilog, I don't think ...
I use Delphi 5 Standard
I use Delphi 5 Standard
ASKER
I have TReplaceDialog but since Delphi is new to me, I don't know how to use it :(
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 :}
"...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 :}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
Neto, everyone, I will remember your input If I ever want more control than this for saving files.
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;