0

I'm trying to compile project wrote in Delphi 2007 with parameter --codepage:1252. At one machine with Windows 10 everything is ok and Spanish strings are displaying correct. When I'm doing the same on computer with Windows 8 parameter --codepage:1252 nothing change. I need this because on computer where it's not working I have teamcity agent. Has anyone similar problem? Or it is possible to achieve proper displaying Spanish characters on non-unicode application without changing it in windows property which required system restart and it's problematic for teamcity server.

EDIT:

On both computers I have set Polish language for non-unicode application and:

  1. Windows 10 - compile with Spanish characters, copy exe file to Spanish PC and there is no Spanish characters.
  2. Windows 10 - compile with Spanish characters and --codepage:1252 parameter set in dproj "1252", copy exe file to Spanish PC and Spanish characters are show correct.
  3. Windows 10 - compile with Spanish characters and --codepage:1252 parameter in command line using dcc32.exe, copy exe file to Spanish PC and Spanish characters there is no Spanish characters.
  4. Windows 8 - compile with Spanish characters, copy exe file to Spanish PC and there is no Spanish characters.
  5. Windows 8 - compile with Spanish characters and --codepage:1252 parameter, copy exe file to Spanish PC and there is no Spanish characters.

What is the difference between compiling by Delphi and using dcc32.exe it should be the same output because Delphi use dcc32 in the same way, I can see it in output.

UPDATE:

After more test I have conclusion: From Delphi IDE compiling with "--codepage:1252" and all files have ANSI format it's work. When I change to UTF-8 wont work. From command line don't work in any cases and combination.

michał
  • 1
  • 2

2 Answers2

1

Delphi 2007 is the last version of Delphi that still uses an Ansi-based RTL/VCL. The native GUI components use the OS's default Ansi codepage. So it does not matter if your source code is encoded in Latin1/Spanish (which is what the --codepage:1252 parameter is telling the compiler) if your GUI cannot display Spanish data correctly on a non-Spanish machine.

As dummzeuch mentioned, your source code should be saved as UTF-8 instead of Latin1/Spanish. But if you want to display Unicode data at runtime from an Ansi-based executable, you will have to convert your data to Unicode and use 3rd party Unicode GUI components, such as the TNT Unicode controls. Also see Handling a Unicode String in Delphi Versions <= 2007.

Otherwise, bite the bullet and upgrade to Delphi 2009 or later, which use a native Unicode-based RTL/VCL. Delphi has been a fully Unicode product since 2008, it is time to ditch ANSI.

Community
  • 1
  • 1
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • But it works when I make compilation from Delphi and have 1252 parameter in dproj file. I compiling Spanish version on Polish language PC. When I do the same by dcc32.exe in command line with parameter --codepage:1252 there is no Spanish characters. – michał Aug 10 '16 at 07:21
  • `DCC_CodePage` and `--codepage` only apply to the encoding of the source code itself. They have no effect on the runtime behavior of the compiled app. Whatever data you have statically defined inside the source code is going to be *interpreted* using the OS codepage at runtime, because you are using a Delphi version that is still based on `AnsiString` and ANSI-based APIs. If your app runs on multiple machines that use different languages, you will have to either perform data conversions at runtime from one codepage to another, or else get away from ANSI completely and use Unicode instead. – Remy Lebeau Aug 10 '16 at 17:10
0

You could, on the computer where it works correctly, change the file format to UTF-8 and save it (I'm not sure whether it is possible to do that automatically for all files in a project. Then it should work on any computer, regardless of its codepage.

To change the file format, use the context menu of the editor window.

dummzeuch
  • 10,975
  • 4
  • 51
  • 158
  • When all my files have ANSI format Spanish chars are correct when I change to UTF-8 I lost it. – michał Aug 10 '16 at 08:58
  • Then I'm out of ideas, sorry. – dummzeuch Aug 10 '16 at 10:20
  • Set the source file encoding to UTF-8, then at runtime use `UTF8Decode()` when passing a string literal to an `AnsiString` variable/property. That will perform a conversion from UTF-8 to whatever ANSI codepage the OS is currently using. – Remy Lebeau Aug 10 '16 at 17:12