[Lazarus] Making sources compatible with Delphi (but Lazarus is priority)

Mattias Gaertner nc-gaertnma at netcologne.de
Mon May 1 13:47:39 CEST 2017


On Sun, 30 Apr 2017 13:37:17 -0300
"Marcos Douglas B. Santos via Lazarus" <lazarus at lists.lazarus-ide.org>
wrote:

> It months ago I realized that Lazarus was saving the sources like that:
> 
> 1- If there is only ANSI chars, save it as ANSI encode;
> 2. If there is more than ANSI chars, save it as UTF8 encode;

Lazarus saves source file by default as UTF-8 without BOM.

 
> (correct me if I'm wrong about that)
> 
> I think this was changed when I updated my FPC to 3.* and Lazarus (trunk).
> Everything continues works. This new behavior was completly transparent to
> me... but I have a doubt:
> 
> If Delphi sources don't use UTF8, how is the best way to mantain sources
> that need to work in both compilers?

Option a) You can use English in sources and load all non ASCII
constants via resourcestrings or similar. Then the codepage is
irrelevant.
Option b) You can store all files as UTF-8 with BOM. Then FPC will
store all non ASCII string constants as unicodestrings. Be careful when
using PChar with them. This adds implicit conversions, so it might be
slower.

Mattias


More information about the Lazarus mailing list