2

I'm trying to translate some parts of a project example where all comment parts and console output are in the Russian language, but when the project is opened via IDE, seems that Code Editor does not recognize this language, example:

enter image description here

Then, exists some setting into IDE (or any other trick) that can solve it (also to any language, not only Russian)?

Thank you.

FLASHCODER
  • 1
  • 7
  • 24
  • 2
    Use UTF-8 as the source code encoding. That will work just fine. I always use a lot of "strange" characters in my source files (mathematical operators etc. in string literals). [But getting the characters to display properly in the console window is a different thing.] – Andreas Rejbrand Mar 19 '20 at 12:07

1 Answers1

3

The Delphi code editor supports non-ASCII (and non-ANSI) characters. Just make sure to use the UTF-8 encoding for the source code.

Screenshot of the Delphi source code editor with Persian text and mathematical operators.

If you enter non-ANSI characters in a previously non-UTF file and try to save, the IDE will ask you if you want to change the encoding to UTF8:

Screenshot of dialog box asking the user if (s)he want to change the encoding to UTF8.

In any case, you can use the editor's context menu to set the encoding:

Screenshot of the code editor's context menu, with the "File Format" submenu open. It contains various kinds of text encodings, such as ANSI and UTF8.

However, the code editor is -- unfortunately -- somewhat buggy when you use non-ANSI characters. For instance, consider the following line of code:

A line of code in the Delphi IDE's editor. It contains Persian and mathematical characters, and ends with a call to the Exit procedure. The caret is within the word "Exit".

If I press Ctrl+W at this point, I expect the word "Exit" to become selected, because that's what Ctrl+W is supposed to do. But the "strange" characters on the line makes the editor all confused, and this is what happens:

A part of the line to the left of "Exit" has become selected.

Here is the line as plain text:

ShowMessage('ریاضیات: (∂/∂t) ∫ sin(xt) dt'); Exit;
Andreas Rejbrand
  • 105,602
  • 8
  • 282
  • 384
  • (This is a bug that really annoys me. I have many files with many string literals containing mathematical operators (automated tests for a mathematical system), and Ctrl+W is one of my favourite shortcuts that I use all the time.) – Andreas Rejbrand Mar 19 '20 at 12:24
  • When i set to UTF-8 nothing happens, not is working, still with strange characters on Code Editor after open project again (even after **Save** when is set to UTF-8). – FLASHCODER Mar 19 '20 at 12:34
  • 1
    @BrowJr You need to open your .pas files in Notepad++, convert encoding from Windows-1251 to UTF-8 (Encoding - Convert to UTF8), save it and only then open they in Delphi. – zed Mar 19 '20 at 12:41