Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2000-12

Wide strings

1 message · 1 person ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Gabor DEAK JAHN

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:

Reply by email