I have not tried Delphi 2009, but uses fpc, which also slowly switches to unicode. I am 95% sure that everything below also applies to Delphi 2009
In fpc (with Unicode support), it will be such that length-type functions take into account the code page. Thus, he will return the length of the string, as a "person", he will see it. If there are, for example, two Chinese characters, both take two bytes of memory in Unicode, the length will return 2, since there are two characters in the string. But the string will occupy 4 bytes of memory. (+ memory for reference counter and lead # 0, but aside)
What you can no longer do is the following:
var p : pchar; begin p := s[1]; for i := 0 to length(string)-1 do begin write(p); inc(p); end; end;
Because this code will - in two examples with a Chinese character - write the wrong two characters. Namely, two bytes that are part of the first "real" character.
In short: Length () no longer returns the number of bytes allocated for the string, but the number of characters. (Before moving to unicode, these two values โโwere equal to each other)
Loesje
source share