Recent

Author Topic: SaveDialog asks for filename although one has been assigned Opendialog also  (Read 786 times)

gjunk

  • New Member
  • *
  • Posts: 33
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

  • Hero Member
  • *****
  • Posts: 5465
    • Bart en Mariska's Webstek
Re: SaveDialog asks for filename although one has been assigned Opendialog also
« Reply #1 on: September 26, 2023, 03:27:11 pm »
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

  • New Member
  • *
  • Posts: 33
Re: SaveDialog asks for filename although one has been assigned Opendialog also
« Reply #2 on: September 26, 2023, 03:50:26 pm »
Thank you.

 

TinyPortal © 2005-2018