Thursday, November 15, 2007

Unicode: SizeOf is Different than Length Part II

One thing I forgot to mention in my last unicode post about SizeOf and Length. You can specify the size in bytes of a buffer two ways correctly:

ByteCount: Integer;
Buffer: array[0..255] of Char;
ByteCount := SizeOf(Buffer); // Version 1
ByteCount := Length(Buffer) * SizeOf(Char); // Version 2
ByteCount := Length(Buffer) * SizeOf(Buffer[1]); // Version 2 with more clarity

I suggest just going with the first version.


Craig said...

Well, this implies that Length returns the "size" in code units, not code points. Which is fine, but it's going to confuse people even if spelled out in Help.

Chris Bensen said...


Honestly I just posted that to be thorough and since there was a comment about prefering to use Length because SizeOf is a little unclear. So this version might be more clear to some.

Post a Comment