[SOLVED] Problem with SaveDialog lazarus / 31-LCL ---------------------------------------------------------------------- madepabloh · 2012-06-07 18:49 May be you could help me with this problem with SaveDialog: I have a memo component, and i want to save its content to a *.csv or a *.txt file. This is the code that i have in a button what calls to this dialog: Code: [Select]procedure TForm1.SpeedButton2Click(Sender: TObject); var   nombre: string; begin    if SaveDialog1.Execute then      begin            nombre := ('Datos_' + FormatDateTime('yyyymmdd',now));            SaveDialog1.FileName := nombre;         try            Memo2.Lines.SaveToFile(SaveDialog1.FileName);         except         end;      end; end; And those are the characteristics of the component: Code: [Select]DefaultExt    *.csv FileName       Datos Filter              *.csv|.csv|*.txt|.txt FilterIndex     1 InitialDir Title              Guardar como It compiles without problem, but the problems comes later and they are: 1) When i open the dialog the filename is the file name assigned in the characteristics, but not what i modified by code in the button 2) When i open a second (and consequent times), FileName is empty. 3) When i click on save, not files are saved 4) the name of the dialog form is "Save file as", and not "guardar como" what is the tittle what i assigned to the SaveDialog component. What i am doing wrong? I checked the forum and the wiki, and the wiki, and my code looks correct... Thanks! ---------------------------------------------------------------------- typo · 2012-06-07 19:11 Try the bugtracker. http://bugs.freepascal.org/view_all_bug_page.php?project_id=1 ---------------------------------------------------------------------- madepabloh · 2012-06-07 19:13 Thanks Typo, I will try. ---------------------------------------------------------------------- jamhitz · 2012-06-07 19:59 This is what I did: Code: [Select]unit TestDialog; {$mode objfpc}{$H+} interface uses   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls; type   { TForm1 }   TForm1 = class(TForm)       btnSave: TButton;       btnOpen: TButton;       btnClose: TButton;       memo2: TMemo;       dlgOpen: TOpenDialog;       dlgSave: TSaveDialog;       procedure btnCloseClick(Sender: TObject);       procedure btnOpenClick(Sender: TObject);       procedure btnSaveClick(Sender: TObject);   private     { private declarations }   public     { public declarations }   end; var   Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.btnCloseClick(Sender: TObject); begin     Self.Close; end; procedure TForm1.btnOpenClick(Sender: TObject); begin     if dlgOpen.Execute then     begin         memo2.Lines.LoadFromFile(dlgOpen.FileName);     end; end; procedure TForm1.btnSaveClick(Sender: TObject); begin     if dlgSave.Execute then     begin         memo2.Lines.SaveToFile(dlgSave.FileName);     end; end; end. It works for me. Hopes it works for you. Cheers! ---------------------------------------------------------------------- madepabloh · 2012-06-07 22:13 @thanks jamhitz,  Ii will try it! On the other hand, i detected that in really, the file is already saved... however, not in the directory marked in the savedialog, just in the same folder then where my application is saved... And it does not care about if i change the name of the file in the savedialog... I will post here any other input what could help me/us to solve this problem! ---------------------------------------------------------------------- DirkS · 2012-06-07 23:58 Quote1) When i open the dialog the filename is the file name assigned in the characteristics, but not what i modified by code in the buttonThat's because you execute the SaveDialog before changing the name. The code should be something like Code: [Select]procedure TForm1.SpeedButton2Click(Sender: TObject); var   nombre: string; begin    nombre := ('Datos_' + FormatDateTime('yyyymmdd',now));    SaveDialog1.FileName := nombre;    if SaveDialog1.Execute then      begin         try            Memo2.Lines.SaveToFile(SaveDialog1.FileName);         except         end;      end; end; ---------------------------------------------------------------------- madepabloh · 2012-06-08 16:06 Perfect @DirkS!!! Your code works now perfect, such as expected!! Thank you very much for solve this problem! Cheers!