[fpc-pascal] Problem with string conversion
vsnijders at quicknet.nl
Fri Oct 20 19:29:03 CEST 2006
Felipe Monteiro de Carvalho schreef:
> On 10/20/06, Vincent Snijders <vsnijders at quicknet.nl> wrote:
>> This should be
>> WideText := GetMem(Size*2);
>> because you get the number of characters, and the number of bytes 2*
>> number of
> Thanks, it works, but I still have doubts.
First of all, I am perfectly happy with using English in all texts, so
all this utf-8 and Unicode is just needless ballast and ascii is just
fine. So I did not delve too deep into it, nor I am going to in the near
> 1) On linux I will need that cwstring unit, right? This was a utf-8
> test to be used on fpGUI, and possibly LCL. So can´t we just add
> cwstring on another unit instead of the first of the program?
As long as you don't need the widestring manager and any functions that
use it, there is no problem putting in any other unit. You just have to
make sure the widestring manager is set (which is what the cwstring unit
does in its initialization section), before you start using the
> 2) Does this work in case my string contains characters bigger then
> #FFFF ? I mean, it seams that we suppose that each character will have
> 2 bytes, but this may not be true.
That depends on the definition of the char count, check the docs of the
function you used (or if the docs are missing, the source of the
function you used and the docs of the function it uses).
> 3) Shouldn´t we allocate Size * 2 + 2? I mean, we did not allocate
> space for the null-terminator.
That depends on the definition the size parameter. See 2. You earlier
version didn't have +1 either and I assumed you had checked that to be ok.
More information about the fpc-pascal