Re: Pre-information on Unicode in Delphi 2008
- From: Eric Grange <egrangeNO@xxxxxxxxxxxxxxx>
- Date: Thu, 29 Nov 2007 10:14:41 +0100
Just as is the case with different types of integers....
Well IMO this is one case where Delphi isn't doing strong typing, there should be a warning there (just like there can be in C++) and a requirement for an explicit cast.
If you don't code for it, then you don't care (or at least can't complain if you get caught out).
Actually I can complain, because the compiler didn't provide me with any warning. Some of those conversions happen not because you didn't care, but because you made mistake.
you better believe that you _might_ experience some data loss. But maybe that's OK. If it's not OK then you code for it:
sA := ANSIEncode(sU);
Most of the time, no, that's not ok.
The first form should trigger a compiler warning, otherwise you're just setting yourself up for zillions of mistakes... just like currently happens between AnsiString and WideString, *whichever* way you're converting.
Converting from Ansi to Wide while assuming the Ansi is using the system_locale is just an assumption, and in the Delphi IDE itself, that can results in string corruption when editing DFMs, and before you ask, yes there are QCs on the subject :)
> since ALL the "String"s in such applications will by definition have
> the same encoding UNLESS the application is ALREADY coding
> specifically for a variety of encodings
I'm not following you there. AnsiString have no particular encoding at all (neither the same, nor the system's), assuming *any* encoding for automagic conversion is going to result in hard-to-track cases of data corruption (since basicly any ":=" becomes suspect).
It only becomes an "issue" for NEW applications specifically mixing difference types of string encodings in their application and then not adequately allowing for those different encodings.
It becomes an issue whenever you're going to have some form of automagic conversion/comparison routine happen.
F.i. if you assume a particular Ansi encoding for a string, then you'll have to honour it for comparisons, and depending on the encoding assumed, the result of the string comparisons will be different.
Different sized/signed integers.
Different precision floats.
These are trouble actually.
Good thing we at least have errors when converting from floats to integers!
Just because it isn't perfectly bulletproof doesn't mean it isn't the best possible (and most practical) approach.
Automagic conversions are neither bulletproof nor practical IME, they're false time savers - just like using one-letter function names all over the place would be ;)
Eric
.
- Follow-Ups:
- Re: Pre-information on Unicode in Delphi 2008
- From: Jolyon Smith
- Re: Pre-information on Unicode in Delphi 2008
- From: Maël Hörz
- Re: Pre-information on Unicode in Delphi 2008
- References:
- Re: Pre-information on Unicode in Delphi 2008
- From: Rudy Velthuis [TeamB]
- Re: Pre-information on Unicode in Delphi 2008
- From: Jolyon Smith
- Re[2]: Pre-information on Unicode in Delphi 2008
- From: Kryvich
- Re: Re[2]: Pre-information on Unicode in Delphi 2008
- From: Jolyon Smith
- Pre-information on Unicode in Delphi 2008
- From: Kryvich
- Re: Pre-information on Unicode in Delphi 2008
- From: Eric Grange
- Re: Pre-information on Unicode in Delphi 2008
- From: Jolyon Smith
- Re: Pre-information on Unicode in Delphi 2008
- From: Eric Grange
- Re: Pre-information on Unicode in Delphi 2008
- From: Jolyon Smith
- Re: Pre-information on Unicode in Delphi 2008
- Prev by Date: Re: Delphi and the .Net platform
- Next by Date: Re: Delphi and the .Net platform
- Previous by thread: Re: Pre-information on Unicode in Delphi 2008
- Next by thread: Re: Pre-information on Unicode in Delphi 2008
- Index(es):
Relevant Pages
|
Loading