Recent

Author Topic: UTF8 filename  (Read 20816 times)

totya

  • Hero Member
  • *****
  • Posts: 720
UTF8 filename
« on: April 20, 2015, 10:44:13 pm »
Hi!

It's a great component, but It seems to me, this component support only ANSI filenames. My request is UTF8 filenames support, if possible.

Thanks to developers!

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4468
  • I like bugs.
Re: UTF8 filename
« Reply #1 on: April 20, 2015, 11:50:03 pm »
It's a great component, ...

Which component?
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: UTF8 filename
« Reply #2 on: April 20, 2015, 11:53:13 pm »
Juha, simply take a look at the title of the subforum (LOL).

I do not understand why you ask questions like this ...(LOL)
« Last Edit: April 21, 2015, 12:16:01 am by typo »

totya

  • Hero Member
  • *****
  • Posts: 720
Re: UTF8 filename
« Reply #3 on: April 21, 2015, 04:18:21 am »
It's a great component, ...

Which component?

Hi!

Yes, see subforum name: fpspreadsheet see http://wiki.freepascal.org/FPSpreadsheet


for example:

Code: [Select]
MyWorkbook.ReadFromFile(UTF8ToSys(FileName));
UTF8toSys conversion needed, but if filename(and/or path) is UTF8, then ReadFromFile doesn't work with this code:

Code: [Select]
MyWorkbook.ReadFromFile(FileName);
First problem is in fpspreadsheet unit:

Code: [Select]
procedure TsWorkbook.ReadFromFile(AFileName: string); overload;
var
  SheetType: TsSpreadsheetFormat;
  valid: Boolean;
  lException: Exception = nil;
begin
  if not FileExists(AFileName) then
    raise Exception.CreateFmt(rsFileNotFound, [AFileName]);   

See, this unit use FileExists function, and not FileExistsUTF8.

I hope you understand this problem now.
« Last Edit: April 21, 2015, 04:23:10 am by totya »

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4468
  • I like bugs.
Re: UTF8 filename
« Reply #4 on: April 21, 2015, 08:30:53 am »
Juha, simply take a look at the title of the subforum (LOL).
I do not understand why you ask questions like this ...(LOL)

Oops ...
My bad.

Anyway, our improved Unicode support very likely solves this problem :
  http://wiki.freepascal.org/Better_Unicode_Support_in_Lazarus
« Last Edit: April 21, 2015, 08:35:34 am by JuhaManninen »
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

Bart

  • Hero Member
  • *****
  • Posts: 5290
    • Bart en Mariska's Webstek
Re: UTF8 filename
« Reply #5 on: April 21, 2015, 10:19:12 am »
I would think that the core of fpspreadsheet does not depend on anything form Lazarus, just fpc.
It would be possible to add a dependency on LazUtils and use TFileStreamUtf8, but that would make the component unusable for non-Lazarus (as in: pure fpc) developers.

Bart

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: UTF8 filename
« Reply #6 on: April 21, 2015, 10:46:18 am »
The main spreadsheet functionality (package laz_fpspreadsheet) depends on FCL and the LazUtils. The visual components (laz_fpspreadsheet_visual) depend also on LCL and TAChart.

Quote from: totya
simply take a look at the title of the subforum (LOL).
I do not understand why you ask questions like this ...(LOL)
And I do not understand why you expect me to take my time to answer your question which you did not take your time to formulate (LOL)

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: UTF8 filename
« Reply #7 on: April 21, 2015, 10:57:58 am »
Quote from: totya
simply take a look at the title of the subforum (LOL).
I do not understand why you ask questions like this ...(LOL)
And I do not understand why you expect me to take my time to answer your question which you did not take your time to formulate (LOL)
Mmmm, I think the quoting is wrong here  %) That was a quote from typo, not totya, and was aimed at the response of JuhaManninen.

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: UTF8 filename
« Reply #8 on: April 21, 2015, 11:08:17 am »
Just a joke, sorry.

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: UTF8 filename
« Reply #9 on: April 21, 2015, 11:15:38 am »
Quote
Mmmm, I think the quoting is wrong here  (http://forum.lazarus.freepascal.org/Smileys/ExcellentSmileys1/wacko.gif) That was a quote from typo, not totya, and was aimed at the response of JuhaManninen.
Sorry - did not read carefully enough (as usual...). But the message remains: if users want somebody else to take their time for answering their questions they should take at least enough of their own time to formulate their questions in an understandable way.

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: UTF8 filename
« Reply #10 on: April 21, 2015, 11:43:03 am »
Hi!

It's a great component, but It seems to me, this component support only ANSI filenames. My request is UTF8 filenames support, if possible.

Thanks to developers!

Try a search and replace in the main fpspreadsheet file:

Search for: TFileStream
Replace with: TFileStreamUtf8

And check if it fixes your problem.

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: UTF8 filename
« Reply #11 on: April 21, 2015, 11:54:03 am »
Search for: TFileStream
Replace with: TFileStreamUtf8
That wouldn't solve the "not FileExists(AFileName)" in the source of fpspreadsheet, which isn't UTF-8 compatible as long as UTF-8 isn't enabled in RTL.

The suggestion from JuhaManninen seems much more promising:
http://wiki.freepascal.org/Better_Unicode_Support_in_Lazarus#Testing_with_Lazarus
(i.e. "Set UTF-8 in RTL)

Quote
File functions in RTL now take care of file name encoding. All (?) file name related ...UTF8() functions can be replaced with the Delphi compatible function without UTF8 suffix. For example FileExistsUTF8 can be replaced with FileExists.
But that would only work with the latest version (FPC 2.7.1).

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: UTF8 filename
« Reply #12 on: April 21, 2015, 11:55:32 am »
But this would make the basic spreadsheet functionality depend on LCL. It the worth the little convenience of not calling AnsiToUTF8/TUF8ToAnsi? Beyond that, there are other TFileStreams spread throughout the package: fpolebasic.pas, fpolestorage.pas, xlsooxml.pas, fpcsvdocument.pas, fpsopendocument.pas, fpsreaderwriter.pas, fpsstreams.pas, fpszipper.pas, fpsxmlcommon.pas

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: UTF8 filename
« Reply #13 on: April 21, 2015, 12:03:11 pm »
Quote from: rvk
That wouldn't solve the "not FileExists(AFileName)" in the source of fpspreadsheet, which isn't UTF-8 compatible as long as UTF-8 isn't enabled in RTL.
Why is this an issue? All strings passed to any fpspreadsheet filename are expected to be ansi, just like for any fpc file procedure. So, for reading a spreadsheet file from Lazarus, call "workbook.ReadFromFile(UTF8ToAnsi(filename))", and the "FileExists" is handled correctly.

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: UTF8 filename
« Reply #14 on: April 21, 2015, 12:48:30 pm »
"workbook.ReadFromFile(UTF8Filename);" would work too if the option is set to "Set UTF-8 in RTL" in the project-options (I think).

I don't think this is a fpspreadsheet issue at all and fpspreadsheet wouldn't even have to know what kind of encoding it's handling. It passes the strings to RTL (i.e. FileExists() ) and if the project-options are set correctly it would work correctly if the RTL can handle these UTF-8 strings (via that option).

 

TinyPortal © 2005-2018