0
votes

we run an 64 bit Delphi XE2 application and store results via the following procedure :

Var MyFilewithresult : TStringList; 

......
...... 
MyFilewithresult.savetoFile('e:\myresults.txt');

on Windows side everything is fine, now problem. But this file must be processed now on a LINUX computer; the software on LINUX claims my windows file format is not correct. I need to apply on LINUX the following manual correction procedure :

$ iconv -f UTF-16 -t ASCII -o myresults.txt myresultsX2.txt
$ dos2unix myresults.txt

How to modify my Delphi app , How to save a Stringlist to write directly ASCII and not Unicode from the 64 bit side .....

I use Delphi XE2, Win 7, x64 OS, I need X 64 for my app

1

1 Answers

3
votes

Specify the encoding when you save the file:

StringList.SaveToFile(FileName, TEncoding.ASCII);

ASCII is a somewhat limited encoding. If you use any characters outside the ASCII range, then they will be lost when you save. You might be better off with UTF-8 which is a full encoding of Unicode, if your Linux program will handle that.

StringList.SaveToFile(FileName, TEncoding.UTF8);

Beware of the BOM that is produced. Your Linux program might not appreciate the use of a BOM. In which case you should set WriteBOM to False before writing the file.