Recent

Author Topic: Unicode filenames  (Read 6692 times)

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Unicode filenames
« on: June 03, 2010, 06:35:10 am »
How do i properly convert string to unicode? If i normally have for example "äö" characters in filenames my texture loader throws errors.

So i tried to look forums and lazarus helps for info but none to found. Here is what i have so far tried but it is either throwing SIGSEGV or giving string with too many random characters at end
Code: [Select]
var temp: PWideChar; filename: string;
...
  //StringToWideChar(filename,temp,length(filename)+1);
  //utf8ToUnicode(temp,length(filename)+1,@filename,length(filename));
  temp:=getmem(length(filename)*2);
  StringToUnicodeChar(filename,temp,256);

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1927

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: Unicode filenames
« Reply #2 on: June 03, 2010, 07:04:45 am »
Sorry i don't even know what to look for and the few examples i tried from wiki didn't help. AnsiToUTF8() UTF8ToAnsi() both ways with FileExists() or FileExistsUTF() always results in file not found with these characters present. Other files still open right.

Edit: By the tutorial, this should work:
Code: [Select]
  temp:=SysToUTF8(filename);
  if not FileExistsUTF8(temp) then
But it is reporting file not found. Same if i ignore FileExists() checks and then try-except-end catches error on JPG image loading. And it is not error in image because it is a copy of working image just added scandic characters in filename.
« Last Edit: June 03, 2010, 07:50:59 am by User137 »

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1927
Re: Unicode filenames
« Reply #3 on: June 03, 2010, 08:04:21 am »
You are on Windows, right?

The question is where the filename comes from.
If it comes from an TOpenDialog or TEdit then simply pass it to
FileExistsUTF8() without conversion.
Try this first.

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: Unicode filenames
« Reply #4 on: June 03, 2010, 08:41:05 am »
Yeah Windows and using TOpenDialog (in this project), it is just passed as normal string. And your suggestion worked indeed  :D  It was FileExists() that had it block in the first place it seems.

Also i had the filenames printed with OpenGL by a generated character map-texture. This needed SysToUTF8() conversion in generation and UTF8toSys() when drawing characters on screen.

All in all they work now.

 

TinyPortal © 2005-2018