Forum > General
Cannot open file - special characters
Pancratius:
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: ---if OpenDialog1.Execute then
Memo1.Lines.LoadFromFile(OpenDialog1.FileName);
--- End code ---
Bart:
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
Pancratius:
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: ---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;
--- End code ---
Bart:
Please upgrade to the 1.4 branch, there this conversion is not needed anymore (because TMemo.LodFromfile/SaveTofile handles it by itself).
Bart
Pancratius:
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?
Navigation
[0] Message Index
[#] Next page