Search code examples
delphinon-ascii-charactersdelphi-10.3-riocode-editor

Code Editor not recognizes Russian characters


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.


Solution

  • 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;