[Lazarus] ForceDirectoriesUTF8

Mattias Gaertner nc-gaertnma at netcologne.de
Sun Mar 3 09:38:54 CET 2013


On Sun, 3 Mar 2013 08:48:30 +0800
Xiangrong Fang <xrfang at gmail.com> wrote:

> > I would think that that depends on where you get the value for
> > ForceDirectories(UTF8) from.
> > If this vale is obtained from any widget (OpenDialog, TEdit, etc.) the
> > encoding of the value is in UTF-8.
> > If however you get the value as a commandline parameter, then it is in
> > system-encoding if you use ParamStr(), but in UTF-8 if you use
> > ParamStrUTF8().
> 
> That's what I guessed, so Instead of using UTF8 version I would use this to
> ensure cross platform correctness:
> 
> Path := SelectDirectoryDialog1.FileName;
> ForceDirectories(UTF8Decode(Path));
> 
> Right? Yesterday I found in this post (which triggered me to ask the
> question initially):
> 
> http://lists.lazarus.freepascal.org/pipermail/lazarus/2012-April/073170.html
> 
> Such problems may (should) go away with the new Unicode- and AnsiString
> types, where AnsiString contains an Encoding field. Then the conversion
> between UTF-8 and the system codepage are done automatically, whenever
> required, and the xyUTF8 functions can be dropped then.

Yes, but it is a long way till all functions and methods are adapted.

 
> If so, we shall avoid using **UTF8 functions at all.

If your program has to work now or with older compilers/libraries you
have to use the *UTF8 functions.

Mattias




More information about the Lazarus mailing list