Subject | Re: [IBO] IBO - IB_String vs AnsiString |
---|---|
Author | m. Th. |
Post date | 2009-04-09T08:31:20Z |
Helen Borrie wrote:
bytes/char whereas in D2007 and earlier is one byte. The CodeGear guys
made a very nice job, making the conversion transparent if the source
code is 'clean' (or perhaps with very few adjustments). The problem
arose from tricky code blocks in which different "workarounds" were
used. Something like:
var
s: string;
begin
FillChar(s, Length(s), #0);
...
//blows up in D2009.
//1st because the actual size of 's' is Length(s)*SizeOf(Char)
//2nd. It's very dangerous to use #0 to mark the end of a string because
in fact all the ASCII chars have in Unicode the 2nd byte #0.
Clean code like:
for i:=0 to Length(s) do s[i]:=' ';
works ok because the compiler knows how to do it.
A solution would be to use the old (now) type 'AnsiString' (the older
String) in the places in which the Unicode isn't needed and/or use an
alias like IB_String = AnsiString compile, make sure if it works, and
convert gradually all the IB_String occurrences to 'String' in order to
gain the Unicode.
What do you (and/or others) say?
m. Th.
> As I don't have Delphi 2009, I have to confess I've no idea what has been done there that seems to create a new problem w.r.t. character sets....so, in essence, I really can't grokk what this thread is all about.The main problem is that in D2009 the 'String' type is Unicode ie. 2
>
> Helen
bytes/char whereas in D2007 and earlier is one byte. The CodeGear guys
made a very nice job, making the conversion transparent if the source
code is 'clean' (or perhaps with very few adjustments). The problem
arose from tricky code blocks in which different "workarounds" were
used. Something like:
var
s: string;
begin
FillChar(s, Length(s), #0);
...
//blows up in D2009.
//1st because the actual size of 's' is Length(s)*SizeOf(Char)
//2nd. It's very dangerous to use #0 to mark the end of a string because
in fact all the ASCII chars have in Unicode the 2nd byte #0.
Clean code like:
for i:=0 to Length(s) do s[i]:=' ';
works ok because the compiler knows how to do it.
A solution would be to use the old (now) type 'AnsiString' (the older
String) in the places in which the Unicode isn't needed and/or use an
alias like IB_String = AnsiString compile, make sure if it works, and
convert gradually all the IB_String occurrences to 'String' in order to
gain the Unicode.
What do you (and/or others) say?
m. Th.