Jump to content
Dave Novo

How to enter unicode symbols into the Delphi IDE

Recommended Posts

Hello,

 

I am trying to use some unicode math symbols as variables to make code more readable. But I cannot seem to find out how to insert unicode characters into my source code. I am using the consolas (the default) font in the editor. 

I saw on the internet some blogs that in other apps you enter the code value and then Alt+X, but that brings up model maker code explorer menu.

Any tips are appreciated.

Share this post


Link to post

For me the easiest way is to use the character map copy - paste it into the source. Tested using

 

var
  Φ: real;
begin
  Φ:=5.8;
  showmessage(FloatToStr(Φ));
end;

 

 

Share this post


Link to post

have you tried changing the file encode to UTF8 instead of ANSII, before insert the char?

 

Despite being something quite peculiar and perhaps something to create future problems with the use of exotic characters, especially when this can bring inconvenience between platforms and editions of the IDE, since the RAD from time to time crashes due to a malfunction in the Editor of Code.

Edited by programmerdelphi2k
  • Like 1

Share this post


Link to post
2 hours ago, Dave Novo said:

you enter the code value and then Alt+X, but that brings up model maker code explorer menu.

Sorry, but that is caused by just a simple RethinkHokeys call to the main menu. 🤷‍♂️

Edited by Uwe Raabe

Share this post


Link to post
55 minutes ago, Dave Novo said:

you enter the code value and then Alt+X

That method only applies to MS Office (Word, Excel, etc).

 

AFAIK this is the only keyboard method that works universally:

In the registry, under the HKEY_Current_User/Control Panel/Input Method, set the EnableHexNumpad value to "1" (it's a REG_SZ value in case you need to add it).

  1. Press and hold the Alt key.
  2. Press the + key on the numeric keypad (I hope you got one 🙂 ).
  3. Type the hexadecimal unicode value.
  4. Release the Alt key.

Share this post


Link to post

Microsoft PowerToys has a Quick Accent feature that also includes Greek symbols etc.

You may find it useful. 

Share this post


Link to post

The PowerToys utility really only does accents and I found it inflexible when I tried (and then abandoned) it. 

I use Wizkey from https://antibody-software.com/wizkey/ even though it has a small cost (and a free trial).  Easy to use either from the keyboard or from a popup menu, which I have set to pop up with two presses of the Control key. This menu is customizable so you can ensure your commonly needed characters are immediately to hand, without having to remember a Unicode value.  The menu has an option to show a full char-map for selection also. Of course it works everywhere, not just in the IDE.

Share this post


Link to post

If the set of used chars is short, you can use templates as well (built-in RAD ones or from cnPack or other helper wizard).

Edited by Fr0sT.Brutal

Share this post


Link to post

As an update to this, I found a lot of success using Live Templates. It is a pain the butt to create all of them, but once they are working, then its is pretty easy. Please see here how to create the live template.

An example of one that inserts the alpha symbol is below. Simply type /alpha<space> and you are good to go. 

 

<?xml version="1.0" encoding="utf-8" ?>
<codetemplate	xmlns="http://schemas.borland.com/Delphi/2005/codetemplates"
				version="1.0.0">
	<template name="\alpha" invoke="auto">
		<description>
		 inserts the σ symbol based on the latex syntax
		</description>
		<author>
		David Novo-Lake
		</author>
		<code language="Delphi" context="methodbody"><![CDATA[σ]]>
		</code>
	</template>
</codetemplate>

 

  • Thanks 1

Share this post


Link to post

That's no alpha symbol in your template, that's a lower case sigma. (Or it's the forum software that broke it.)

 

Care to share those templates?

Share this post


Link to post

ugh. sorry, I was in the middle of creating a whole bunch of templates for different greek letters and was copying and pasting. Just change the \alpha to \sigma. Or replace the sigma symbol inside the CDATA and Description with an alpha.

The other thing I found is that the template above will not insert the symbol into a comment. if you change the context to "comments" then it does, although seems to sometimes put it in the wrong spot when inside the comments. It seems to work fine in the method body. Also, inside the comment it is intermittent if it works automatically or you have to press CTRL+J or Ctrl+Space after entering the template name.

 

Below is the alpha template

<?xml version="1.0" encoding="utf-8" ?>
<codetemplate	xmlns="http://schemas.borland.com/Delphi/2005/codetemplates"
				version="1.0.0">
	<template name="\alpha" invoke="auto">
		<description>
		 inserts the α symbol based on the latex syntax
		</description>
		<author>
		David Novo-Lake
		</author>
		<code language="Delphi" context="comment"><![CDATA[α]]>
		</code>
	</template>
</codetemplate>

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×