# AnsiString vs Utf8String properly declared, Delphi: we no longer force AnsiString to UTF-8

**URL:** https://forum.castle-engine.io/t/ansistring-vs-utf8string-properly-declared-delphi-we-no-longer-force-ansistring-to-utf-8/2207
**Category:** News
**Created:** [September 30, 2026, 8:09pm UTC](https://forum.castle-engine.io/t/ansistring-vs-utf8string-properly-declared-delphi-we-no-longer-force-ansistring-to-utf-8/2207 "2026-09-30T20:09:20Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![michalis](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/michalis/32/3_2.png) [@michalis](https://forum.castle-engine.io/u/michalis)
#### Post date: [September 30, 2026, 8:09pm UTC](https://forum.castle-engine.io/t/ansistring-vs-utf8string-properly-declared-delphi-we-no-longer-force-ansistring-to-utf-8/2207/1 "2026-09-30T20:09:20Z")

</div>

| [![Running Castle Game Engine application on Android using Delphi](https://forum.castle-engine.io/uploads/default/original/2X/e/edc5bad0496746e2af15549f5fb23c521c5552eb.png)](https://castle-engine.io/wp/wp-content/uploads/2026/09/delphi_android_platformer.png "Running Castle Game Engine application on Android using Delphi") |

( _This announcement is a bit non-exciting small improvement around the engine codebase. For something more exciting, that I was working on through September, see the screenshot attached here :), and stay tuned for more news soon._ )

Previously, our engine did `SetMultiByteConversionCodePage(CP_UTF8)` forcing all AnsiStrings (with both FPC and Delphi) to have UTF-8 encoding. This is also consistent with what Lazarus LCL was (and still is) doing.

We have extended our possibilities now, and changed what happens with Delphi _by default_ (with FPC, nothing changes by default):

1. Throughout the engine, we use now always `Utf8String` when we want to say _“8-bit string with UTF-8 encoding”_. Aside from the practical gains (see below), this naturally just looks better: we explicitly express our intention.

We use `AnsiString` in code only when (very seldom) we really mean _“8-bit string with whatever encoding happens to be the platform default”_.

We have tested that with Delphi (unfortunately, not so with FPC) the proper implicit conversions are always done when you assign between `AnsiString` (even if they have non-UTF-8 content) and `Utf8String`. See lots of new automatic tests in

  - [testcompiler.pas](https://github.com/castle-engine/castle-engine/blob/master/tests/code/testcases/testcompiler.pas)
  - [testcastleifc.pas](https://github.com/castle-engine/castle-engine/blob/master/tests/code/testcases/testcastleifc.pas)
  - [testfpjson.pas](https://github.com/castle-engine/castle-engine/blob/master/tests/code/testcases/testfpjson.pas)
  - [testcastlescenecore.pas](https://github.com/castle-engine/castle-engine/blob/master/tests/code/testcases/testcastlescenecore.pas)
  - [testcastleclassutils.pas](https://github.com/castle-engine/castle-engine/blob/master/tests/code/testcases/testcastleclassutils.pas)
  - [testcastledownload.pas](https://github.com/castle-engine/castle-engine/blob/master/tests/code/testcases/testcastledownload.pas)

Note: 90% code of the engine still uses just `String` (not `Utf8String` or `AnsiString`). That is deliberate and simple: we want to just use default string type, which means `UnicodeString` (`String=UnicodeString` with Delphi, or [FPC Unicode RTL](https://wiki.freepascal.org/FPC_Unicode_RTL)) or `AnsiString` (FPC, without [FPC Unicode RTL](https://wiki.freepascal.org/FPC_Unicode_RTL)). Nothing changes in this regard.

2. We added defines to control whether the engine does `SetMultiByteConversionCodePage(CP_UTF8)`, forcing all `AnsiString` to contain UTF-8. And by default, it is no longer done when compiled with Delphi.

3. Along the way, we have also fixed and simplified some details around how Unicode characters are handled.

For more details about how `CASTLE_ANSISTRING_FORCE_UTF8` and `CASTLE_ANSISTRING_UNCHANGED` work see

- [CASTLE\_ANSISTRING\_xxx symbols, AnsiString vs Utf8String](https://github.com/castle-engine/castle-engine/blob/master/doc/miscellaneous_notes/ansistring_encoding.md)

- Updated/extended coding conventions about String: https://castle-engine.io/coding\_conventions#strings\_unicode

- And for really all details, see [all 57 commits of this change](https://github.com/castle-engine/castle-engine/compare/ab131f3d0d046d60b6392e1ddc1355c576597fc8...c3755020020ff1bd68f467e811b0bf6c6ba7fc5f) on GitHub.

If you like our work, please [support us on Patreon](https://www.patreon.com/c/castleengine)!
