Forum > General
Dealing with Unicode Filenames
(1/1)
Harrison:
Alright, I've found this thread and this page, and neither seem to be helping me at all.
From what I've read, if a filename contains a unicode character, it needs to be converted to UTF-8. This is an example of how my code was before:
if OpenDialog.Execute then
begin
LoadedFile := TMemoryStream.Create;
LoadedFile.LoadFromFile(OpenDialog.FileName);
end;
Of course, when loading a file with a unicode character in its name, it would error and say that it could not be opened. So I tried this:
if OpenDialog.Execute then
begin
LoadedFile := TMemoryStream.Create;
LoadedFile.LoadFromFile(SysToUTF8(OpenDialog.FileName));
end;
But it still errored. I also tried AnsiToUTF8, and as a last ditch effort, ExpandFileNameUTF8, but they all resulted in the same error.
So, what am I missing? From what I'm reading, this should be right, shouldn't it?
theo:
UTF8ToSys
Harrison:
%) That worked. Mind explaining to me why it seems to be backwards than what the page is saying?
theo:
--- Quote from: Harrison on June 18, 2010, 03:00:35 pm --- %) That worked. Mind explaining to me why it seems to be backwards than what the page is saying?
--- End quote ---
It's not. It's saying:
--- Quote ---Lazarus controls and functions expect filenames and directory names in utf-8 encoding, but the RTL uses ansi strings for directories and filenames.
--- End quote ---
You get the name from a lazarus control (OpenDialog) in UTF8 and pass it to a RTL Function.
So UTF8ToSys is needed.
Navigation
[0] Message Index