[fpc-pascal]Wide strings
Gabor DEAK JAHN
djg at argus.vki.bke.hu
Mon Dec 25 11:34:07 CET 2000
Hello,
Quite a few Win32 functions and procedures require wide (Unicode) strings as
arguments (simple ones come in two flavors, both ANSI and Unicode, but
sophisticated ones like those connected to COM and OLE are Unicode-only).
These strings are, from the programmer's point of view, similar to PChars
but the individual characters are two bytes long). There is a function to
convert between the two formats, however, when the string in question is
constant, this is rather uncomfortable.
LCC (a free C compiler) uses the following notation (note the L right before
the literal):
char *MethodID = L"ViewCopyEditor"
However, in FPC I found no better way than to write:
MethodID : PChar =
'V'#0'i'#0'e'#0'w'#0'C'#0'o'#0'p'#0'y'#0'E'#0'd'#0'i'#0't'#0'o'#0'r'#0#0;
which is, although technically equivalent, rather clumsy. The cleanest
solution would probably be to introduce a new simple type, widechar, which
occupies 2 bytes and, unlike word, does accept a typed-constant
initialization like PChar does:
type
PWideChar = ^widechar;
const
MethodID : PWideChar = 'ViewCopyEditor';
Regards,
Gabor DEAK JAHN
-------------------------------------------------------------------
Gabor DEAK JAHN -- Budapest, Hungary.
WWW: <http://www.tramontana.co.hu/>www.tramontana.co.hu
E-mail: djg at tramontana.co.hu
More information about the fpc-pascal
mailing list