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

5

12

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?

Balky answered 15/11, 2009 at 0:21 Comment(0)
D
3

AFAIK, there is no IDE-wide setting for specifying the default file format.

Dreadful answered 18/11, 2009 at 21:56 Comment(4)
However the IDE does prompt you, when you enter a unicode character into the editor buffer, and then click Save.Pibroch
Rob kennedy suggested that you can in fact, add a new Unit that is saved in UTF8 format to the Object Repository, and then use that from the File -> New menu. I found that it has to contain a high unicode character codepoint in order to keep the UTF8 encoding in new units though.Pibroch
There's a setting as explained in this answer.Nozicka
With 10.4 there is now an option in the IDE.Commit
C
12

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.

Commit answered 14/12, 2017 at 12:49 Comment(0)
E
7

Right-click on your source code in the Delphi 2009 IDE, and select File Format. Then choose UTF-8. Hope that helps.

Estienne answered 15/11, 2009 at 0:42 Comment(4)
I think the question was about doing that by default, so a new file starts off being set to UTF8.Brundage
This does not change the default file format for new files to UTF8, it has an effect only for the current file.Balky
Not the original question but did help me :-)Intertwine
In Delphi 12.1, into the editor page, at the bottom line, here you find a list of combo-box-like items, and if you see "ANSI" change it to "UTF-8"Ismaelisman
P
7

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

Paraglider answered 28/1, 2021 at 13:25 Comment(2)
You're right it's just from 10.4 version, I checked in 10.3.2 and the option doesn't exist.Euler
@Darkendorf: It is still okay though I think, since you can set the option manually in the Windows Registry...Paraglider
R
4

If you install UTF8ize Plugin (english translation of his page & latest version) to your IDE, when you edit any file within the IDE, the plugin set the file's codepage to UTF8 automatically.

(FYI: The author creates many useful plugins. I posted some of his plugins with image here, but my post was deleted by the modelator. I just wanted to know his useful plugins, but yes, it's off topic here. sorry.)

Redware answered 8/10, 2015 at 14:14 Comment(0)
D
3

AFAIK, there is no IDE-wide setting for specifying the default file format.

Dreadful answered 18/11, 2009 at 21:56 Comment(4)
However the IDE does prompt you, when you enter a unicode character into the editor buffer, and then click Save.Pibroch
Rob kennedy suggested that you can in fact, add a new Unit that is saved in UTF8 format to the Object Repository, and then use that from the File -> New menu. I found that it has to contain a high unicode character codepoint in order to keep the UTF8 encoding in new units though.Pibroch
There's a setting as explained in this answer.Nozicka
With 10.4 there is now an option in the IDE.Commit

© 2022 - 2024 — McMap. All rights reserved.