Special behavior of STRING_TO_BUF / WSTRING_TO_BUF
For the STRING/WSTRING data type the FB handling is different. If a string is applied to the BUFFER output, it is assumed that this string is a runtime system formatted string having a 4 byte header and a terminating zero character (see the following note). In case of a format change (Little-/Big-Endian) this header is converted; whereas variables, having other data types like an array of BYTE or WORD connected to the parameter BUFFER indicate that the string applied is a single byte string without a header (for a STRING value) and a UTF16 string without a header (for a WSTRING value). This string must also be terminated with a zero.
Note
In a STRING, each character is represented by one byte and in a WSTRING each character is represented by two bytes. |
Note
It is not allowed to mix the data types STRING and WSTRING on the SRC/BUFFER parameters. |
For the STRING/WSTRING data type the size to be copied assigned in BUF_CNT is limited to 32767 bytes (maximum allowed STRING length). In case of a larger size, ERROR is set to TRUE and STATUS gets the value 10.
If the source STRING/WSTRING has less characters than requested by the parameter BUF_CNT, only the available characters are copied to the destination and the rest is filled up with zeros. One terminating zero character is set at the end of the copied characters every time.
If the destination byte stream is not a STRING/WSTRING, the necessary free memory in the destination consists of the bytes to be copied, the offset in the destination and the terminating zero character. If the destination is less than necessary, ERROR is set to TRUE and STATUS gets the value 7.
If the destination byte stream is a STRING/WSTRING, the necessary free memory in the destination consists of the bytes to be copied, the offset in the destination, the size of the string header and the terminating zero character. If the destination is less than necessary, ERROR is set to TRUE and STATUS gets the value 7.