[...] The problem is that there can only be one variable encoding (as in encoding set on startup) at the moment. [...]
That's also how as I've understood the situation.
"utf8string" as a type has no special handling in the compiler.
I'm not exactly requesting an additional "special handling". What I've got in mind is rather a way to define a string type with ANSI (= GetACP of the running computer) as a static code page value.
As I can see it, the problem is that here is no difference between current encoding and Windows encoding: i.e. CP_ACP means in fact DefaultSystemCodePage, and not necessarily Windows.GetACP. While CP8_UTF8 always means UTF8.
So, having an additional TSystemCodePage type would be great IMHO:
{ some values which are used in RTL for TSystemCodePage type }
const
CP_ACP = 0; // default to ANSI code page
CP_OEMCP = 1; // default to OEM (console) code page
CP_UTF16 = 1200; // utf-16
CP_UTF16BE = 1201; // unicodeFFFE
CP_UTF7 = 65000; // utf-7
CP_UTF8 = 65001; // utf-8
CP_ASCII = 20127; // us-ascii
CP_NONE = $FFFF; // rawbytestring encoding
plus CP_REALACP = xxxx; // ALWAYS to ANSI code page = Windows.GetACP
And this way, an "ansistring" type could be redefined as:
type
ansistring = type ansistring( CP_REALACP );
and not as "ansistring( CP_ACP )", as it's currently the case.
But I admit I don't know enough this Free Pascal part, in order to know if it's possible (not even to know if it really makes sense). Though I understand it's currently not possible without some additions.