Forum > Beginners
SaveDialog asks for filename although one has been assigned Opendialog also
(1/1)
gjunk:
Latest versions of FP and Lazarus.
How do I stop windows from requesting a file name?
I am sending a full path and a file name with an extension.
procedure TForm4.Button2Click(Sender: TObject); //Save form
Var sr:srpt; // shift record
f:file of srpt;
fname:String;
begin // savedialog only saves the memo field
// save edit fields into shfname1 EDT.
saveDialog1.Filename:=ExtractFilepath(ParamStr(0))+ShFname;
ShowMessage(saveDialog1.FileName); //c:\lazprj\sql3\createdb\shftrpt.dat
if SaveDialog1.Execute then
Memo1.Lines.SaveToFile(SaveDialog1.FileName) //shows c:\lazprj\sql3\createdb\shftrpt
else Showmessage('Memo not saved'); // without the extension.
// now we need to save the edit fields
fillchar(sr,sizeof(Sr),0);
sr.Store:=Edit1.text;
sr.date:=Edit2.text;
sr.Shift:=Edit3.Text;
Fname:=ExtractFilepath(ParamStr(0))+Shfname1; // shfname1 is shftrpt.edt
ShowMessage(fname);
Assignfile(f,fname) ; // Assign(f,fname) pulls up Tpersistent
{$I+} rewrite(f); {$i-} // Why?
if ioresult=0 then
Write(f,sr);
ShowMessage(fname+' written.');
Closefile(f);
end;
Bart:
I don't understand the question.
You execute a TSaveDialog.
It's only purpose is to ask the user for a filename.
If you don't want to prompt the user for a name, don't use this dialog.
You can use a simple MessageDialog to ask the user if (s)he is OK to save the file with the suggested filename.
As a side note: saving files in the directory where the program resides is usually not a good idea (because of permission issues).
Bart
gjunk:
Thank you.
Navigation
[0] Message Index