Recent

Author Topic: [Solved]: SynEdit.Lines.SaveToFile not creating correct file extension  (Read 403 times)

JdeHaan

  • Full Member
  • ***
  • Posts: 150
Hi,

I'm running Lazarus & FPC on MacOS Sequoia, both from Trunk (Lazarus 3.99 (rev main_3_99-2668-g6b352d830e) FPC 3.3.1 x86_64-darwin-cocoa)

I'm using a SynEdit to save a file under a specific file extension, which is not a standard one, e.g. file.solv
Every time I create a new file name and try to save it as "filename.solv" automatically an additional extension is added: ".s", so that the file name becomes "filename.solv.s".
I have to continuously remove the ".s" which is really annoying  :(

Anyone knows a trick to create the file without the ".s" extension?
« Last Edit: October 06, 2024, 09:13:08 pm by JdeHaan »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10562
  • Debugger - SynEdit - and more
    • wiki
Re: SynEdit.Lines.SaveToFile not creating correct file extension
« Reply #1 on: October 06, 2024, 06:21:24 pm »
I have no idea where that may come from. Looking at
   procedure TSynEditLines.SaveToFile(const FileName: string);
There is nothing added to the filename.

Just run your app in the debugger, set a breakpoint, and step into the code, and find out where it happens.

You may need to open the SynEdit package, go to options and enable debug info and set it to "dwarf".

Bart

  • Hero Member
  • *****
  • Posts: 5469
    • Bart en Mariska's Webstek
Re: SynEdit.Lines.SaveToFile not creating correct file extension
« Reply #2 on: October 06, 2024, 06:48:48 pm »
Do you actually mean that
Code: Pascal  [Select][+][-]
  1.  SynEdit1.Lines.SaveToFile('test.solv');
creates a file called 'test.solv.s'?

Or do you use a TSaveDialog to get the filename like:
Code: Pascal  [Select][+][-]
  1.   if SaveDialog1.Excute then
  2.     Synedit1.Lines.SaveToFile(SaveDialog1.FileName);

In the latter case check wether of not SaveDialog1.FileName actually contains what you think it should.

Bart

JdeHaan

  • Full Member
  • ***
  • Posts: 150
Re: SynEdit.Lines.SaveToFile not creating correct file extension
« Reply #3 on: October 06, 2024, 08:31:54 pm »
I'm using the following code, which is a TAction, called from pushing the 'Save' button.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FileSaveExecute(Sender: TObject);
  2. begin
  3.   if TabSheet1.Caption <> sUntitled then
  4.     begin
  5.       SynEdit.Lines.SaveToFile(SavedState.LastFolder + '/' + SavedState.LastFileName);
  6.       SynEdit.Modified := False;
  7.       StatusBarUpdate;
  8.     end
  9.   else
  10.     begin
  11.       FileSaveAs.Dialog.FileName := sUntitled + SavedState.FileExtension;
  12.       FileSaveAs.Execute;
  13.     end;
  14. end;
  15.  

Basically, if the file already has a name, clicking Save will just call SynEdit.Lines.SaveToFile with the current filename. This works OK.
But, when the name is 'untitled', I want the SaveDialog to show: 'untitled.solv', after which the user can change the name. After this action the ".s" is added when saved to disk.

JdeHaan

  • Full Member
  • ***
  • Posts: 150
[Solved]: SynEdit.Lines.SaveToFile not creating correct file extension
« Reply #4 on: October 06, 2024, 09:12:28 pm »
Solved it!

Had to add this line to the code:

FileSaveAs.Dialog.Filter := 'Solver files|*.solv|Text files|*.txt';

Code: Pascal  [Select][+][-]
  1.       FileSaveAs.Dialog.Filter := 'Solver files|*.solv|Text files|*.txt';
  2.       FileSaveAs.Dialog.FileName := sUntitled + SavedState.FileExtension;
  3.       FileSaveAs.Execute;
  4.  

 

TinyPortal © 2005-2018