Lazarus

Free Pascal => General => Topic started by: Pancratius on July 28, 2015, 04:50:45 pm

Title: Cannot open file - special characters
Post by: Pancratius on July 28, 2015, 04:50:45 pm
Hi, I written a simple texteditor with TMemo. The program itself shows special characters like å,ä,ö correctly. TMemo works perfect in that sense, but when I save the textfile with scandinavian characters, like Namnlös.txt (Unnamed.txt) the filename gets garbled - Namnlös.txt and my texteditor wont open it. Even when I rename the file in Explorer to namnlös.txt again, the editor wont open it. Why cannot files with special characters be opened?

This is how I open files in the program:
Code: [Select]
if OpenDialog1.Execute then
   Memo1.Lines.LoadFromFile(OpenDialog1.FileName);
Title: Re: Cannot open file - special characters
Post by: Bart on July 28, 2015, 06:11:52 pm
Which Lazarus version?

I have tested with trunk and 1.4 fixes branch.
I can even open (with Memo1.lines.LoadFromFile) files that are named like "C:\Users\Bart\LazarusProjecten\sbp\test\บลูเบอ\บลูเบอ.txt" (notice that the filename contains characters (unicide codepoints) that are outside my current codepage (I'm on Windows)).

Bart
Title: Re: Cannot open file - special characters
Post by: Pancratius on July 31, 2015, 02:20:02 am
I use Lazarus version 1.2.6, it's from April this year.

I have changed my code. Now I can save files with scandinavian characters without the filenames being garbled. But now the characters get garbled within TMemo instead.

This is what the code looks like
Code: [Select]
procedure TForm1.Button1Click(Sender: TObject);
begin
  if SaveDialog1.Execute  then
   Memo1.Lines.SaveToFile(UTF8ToSys(Savedialog1.Filename));
end;

procedure TForm1.Button2Click(Sender: TObject);
begin

  if OpenDialog1.Execute then
   Memo1.Lines.LoadFromFile(SysToUTF8(Opendialog1.FileName));
end;                 
Title: Re: Cannot open file - special characters
Post by: Bart on July 31, 2015, 04:43:07 pm
Please upgrade to the 1.4 branch, there this conversion is not needed anymore (because TMemo.LodFromfile/SaveTofile handles it by itself).

Bart
Title: Re: Cannot open file - special characters
Post by: Pancratius on July 31, 2015, 10:16:42 pm
Muchos gracias Bart. This latest Lazarus runs much faster than the previous one, and filenames and characters within documents shows up the way the should. I found that Notepad gives you the option to save textdocuments in UTF8. If I save them in default ANSI, special characters become questionmarks.

I would like to perform an hecatomb to you in my gratitude. Where to do I deliver the bovides?
Title: Re: Cannot open file - special characters
Post by: Bart on July 31, 2015, 11:09:17 pm
I would like to perform an hecatomb to you in my gratitude. Where to do I deliver the bovides?

 :D :D :D :D

Bart
TinyPortal © 2005-2018