Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I set the default file format in the Delphi IDE to UTF8?

Delphi 2009 sets the default file format for new source code files to ANSI, this makes the source code platform-dependent.

Even for a new XSD file created in the IDE, which by default starts with this line

<?xml version="1.0" encoding="UTF-8" ?>

Delphi sets the file format to ANSI (this looks like a bug, for new XML and XSLT documents UTF8 is selected by default).

Is there a hidden option to set the default file format for source code files?

like image 462
mjn Avatar asked Nov 15 '09 00:11

mjn


People also ask

What is the file extension for utf8?

It uses files with . wri extension as output files that are generated by the software.

Are .txt files UTF-8?

Most Microsoft Windows text files use "ANSI", "OEM", "Unicode" or "UTF-8" encoding.


2 Answers

Although the answer from MBulli should be still relevant, since version 10.4 of Delphi (as far as I remember) it is possible to change the default encoding within the IDE.

Go to Tools > Options and choose User interface > Editor from the navigation area.

You will find the Default file encoding setting down below.

Options window

like image 103
Jacek Krawczyk Avatar answered Oct 31 '22 17:10

Jacek Krawczyk


In fact this blog post from 2004 mentions a hidden IDE option. It states that you can set a default file filter in the registry to make UTF-8 the default encoding in Delphi 8. This still works under Tokyo! Clearly, you have to adapt the path of the registry key to recent versions like this:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Embarcadero\BDS\19.0\Editor]
"DefaultFileFilter"="Borland.FileFilter.UTF8ToUTF8"

After setting this value Delphi will encode new units in UTF-8 with BOM.

like image 34
MBulli Avatar answered Oct 31 '22 18:10

MBulli