"Short Strings" are "Ansi" String, because there are only available for backward compatibility of pre-Delphi code.
st: string[3];
will always create a fixed-length "short string" with the current Ansi Code Page / Char Set, since Delphi 2009.
But such short strings are NOT the same than so called AnsiString
. There is not code page for short strings. As there is no reference-count for short strings.
The code page exists only for AnsiString
type, which are not fixed-length, but variable-length, and reference counted, so a completely diverse type than a short string defined by string[...]
.
You can't just mix Short String
and AnsiString
type declaration, by design. Both are called 'strings' but are diverse types.
Here is the mapping of a Short String
st[0] = length(st)
st[1] = 1st char (if any) in st
st[2] = 2nd char (if any) in st
st[3] = 3rd (if any) in st
Here is the memory mapping of an AnsiString
or UnicodeString
type:
st = nil if st=''
st = PAnsiChar if st<>''
and here is the PSt: PAnsiChar
layout:
PWord(PSt-12)^ = code page
PWord(PSt-10)^ = reference count
PInteger(PSt-8)^ = reference count
PInteger(PSt-4)^ = length(st) in AnsiChar or UnicodeChar count
PAnsiChar(PSt) / PWideChar(PSt) = Ansi or Unicode text stored in st, finished by a #0 char (AnsiChar or UnicodeChar)
So if there is some similarities between AnsiString
and UnicodeString
type, the short string
type is totally diverse, and can't be mixed as you wished.