I am using C++Builder 10.3 Rio developing a multi-platform app for Android.
I have an array of data as follows:
typedef struct recordstruct
{
bool shop;
bool bought;
wchar_t description[80];
} recordtype;
recordtype MasterItems[MAXITEMS]=
{
false,false,L"Apples",
false,false,L"Apricots",
false,false,L"Avocado",
...
...
};
I've copied this into a TEdit, and want to get the value back to the MasterItems array.
I used to use c_str() and mbstowcs() and strcpy()/wcscpy() etc.
How can I do this please ?
UnicodeStringis a UTF-16 encoded string on all platforms. However,wchar_tis a 16bit type used for UTF-16 data only on Windows. On other platforms,wchar_tis a 32bit type used for UTF-32 data.This is documented in Embarcadero's DocWiki:
String Literals char16_t and wchar_t on macOS and iOS
(Android is included, too)
To ensure UTF-16 is used on all platforms, the
System::WideChartype is an alias forwchar_ton Windows andchar16_ton other platforms.UnicodeStringis a container ofWideCharelements.So, if you use
wchar_tfor your array, then on non-Windows platforms you will need to first convert yourUnicodeStringto UTF-32 at runtime, such as with the RTL'sUnicodeStringToUCS4String()function, before you can then copy that data into your array, eg:Otherwise, if you want to ensure your array is always 16bit UTF-16 on all platforms, then you need to use
char16_torWideCharinstead ofwchar_tin your array. Theuprefix creates achar16_t-based literal, and the RTL's_D()macro creates aWideChar-based literal (usingLoruaccording to platform), eg: