[Lazarus] ForceDirectoriesUTF8
Mattias Gaertner
nc-gaertnma at netcologne.de
Sun Mar 3 10:20:27 CET 2013
On Sun, 3 Mar 2013 16:42:33 +0800
Xiangrong Fang <xrfang at gmail.com> wrote:
> > If your program has to work now or with older compilers/libraries you
> > have to use the *UTF8 functions.
> >
> > But the problem is, my program works on both Linux and Windows 7 using
> ForceDirectories (NOT the UTF8 version), and btw, I am running Chinese
> Version of Windows 7.
>
> Could you please tell me what error could happen if I do not use the UTF8
> version?
For example:
ForceDirectories(SelectDirectoryDialog1.Filename);
SelectDirectoryDialog1.Filename is an UTF-8 string,
while ForceDirectories expects system encoding, which might be an 8-bit
windows codepage. It fails on any non ASCII character.
ForceDirectories(UTF8Decode(SelectDirectoryDialog1.Filename));
UTF8Decode converts to widestring, which is then converted to string in
system encoding. It fails on any character not in the system codepage,
including invalid UTF-8 characters.
ForceDirectoriesUTF8 is smarter, as it omits unneeded
conversions on UTF-8 systems and thus supports invalid UTF-8
characters and it uses the *W functions under Windows.
Mattias
More information about the Lazarus
mailing list