How can I write UNICODE-words IN file(td51)

Discussion forum about all things Team Developer 5.x and 6.x
hotenise

How can I write UNICODE-words IN file(td51)

Post by hotenise » 26 Oct 2007, 18:54

I use salfileopen function to create or append a file,

when I use salfilewrite function to write a string in file,

string of ascii is fine.But string of unicode was wrote

null.



code:



Call SalFileOpen(hFile,'C:\\filetest.txt',OF_Create)

Call SalFileWrite(hFile,'12345')

Call SalFileClose(hFile)

-------

filetest.txt--->12345





Call SalFileOpen(hFile,'C:\\filetest.txt',OF_Create)

Call SalFileWrite(hFile,'綉衣æœ

Jean-Marc Gemperle

Re: How can I write UNICODE-words IN file(td51)

Post by Jean-Marc Gemperle » 30 Oct 2007, 09:58

Hi Kevin



Everything is UTF-16 in TD 5.1. When writing a file as it used to be with previous version the result is an ANSI file. So we convert from UNICODE to ANSI using your local page...If you have mixed UNICODE charset some not being part of you local page the conversion beeing done will fail with "?" for those char. To save data as UNICODE use OF_UTF16 flag in SalFileOpen() this will create a unicode file and all charset can be saved then.



As you can see, currently it is not possible to directly open and read properly an ANSI file of a different code page say ARABIC CP1256, nor it is possible to convert UNICODE ARABIC charset to ANSI CP directly. You can do that INDIRECTLY by opening the file as OF_BINARY and make the conversion of the buffer using SalStrToMultiByte()/SalStrToWideChar() with the right code page (the constant we define there are not limited to what we give in the coding assistant)...So you can use 1256 as a code page to this function, this works as long as the code page is installed on your machine. See http://msdn2.microsoft.com/en-us/library/ms776446.aspx



I believe we will improve SalFileOpen to allow this to be done automatically by passing the Code Page you like to use.



Jean-Marc

Return to “General Discussion”

Who is online

Users browsing this forum: [Ccbot] and 0 guests