Question

I'm trying to write file without BOM in RadStudio XE3.

Im using TStreamWriter Helper classes for the purpose. The problem is that Everytime BOM is writed at the beginnig of the file. I want to avoid this. I tried already to change TEncoding, i tried almost all options without success. Embarcadero documentation says that if i write file with UTF7 encoding BOM will not be writed to file (again without success).

Am i wrong or is this a compiler issue?

Was it helpful?

Solution

If the TEncoding used with TStreamWriter defines a BOM, TStreamWriter will write it. There is no option to disable that logic.

One way to avoid the BOM would be to derive a new class from TEncoding that overrides the virtual GetPreamble() method to return an empty byte array, and overrides the other methods to delegate work to another TEncoding.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top