Forum > Beginners

SaveDialog asks for filename although one has been assigned Opendialog also


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;

begin                     // savedialog only saves the memo field
                          // save edit fields into shfname1 EDT.
  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
   Fname:=ExtractFilepath(ParamStr(0))+Shfname1; // shfname1 is shftrpt.edt
   Assignfile(f,fname)   ;                     // Assign(f,fname) pulls up  Tpersistent
   {$I+}  rewrite(f);  {$i-}                   // Why?
   if ioresult=0 then
   ShowMessage(fname+' written.');

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).


Thank you.


[0] Message Index

Go to full version