3

Is it possible to enter from keyboard special Unicode characters, link the ones below?

U+2603  ☃   SNOWMAN
U+2604  ☄   COMET
U+2605  ★   BLACK STAR
U+2606  ☆   WHITE STAR
U+2607  ☇   LIGHTNING
U+2608  ☈   THUNDERSTORM
U+2609  ☉   SUN
U+260A  ☊   ASCENDING NODE
U+260B  ☋   DESCENDING NODE

I would like for example to have buttons with up/down arrows in them, without loading images.

I have tried entering Alt+08593 on keyboard but other character (than the expected arrow) will be inserted.


Update:
The reason for this is LAZINESS. I am too lazy to search for icons or create my own icons. For example you can simply replace the notorious 'save' floppy disk icon. Just take a look at: . BAM! Nice. Right?

Update:
It seems some characters such as (green book = 128215) are not accepted by Delphi, with copy/paste.

Update:
There is nice component that allows you to put unicode chanracters in a image list:
https://github.com/EtheaDev/IconFontsImageList

Gabriel
  • 20,797
  • 27
  • 159
  • 293
  • @MatheusOliveira-Come on! I just said I don't want that (for my reasons). Please do read the question :) – Gabriel Oct 05 '16 at 14:33
  • Ok. I have a solution: Delphi won't let you to directly type the unicode code BUT you can type it in Word (or other unicode editor) and then copy past it in Delphi. Works! Cool buttons without dreadful image lists (and Photoshop work). – Gabriel Oct 05 '16 at 14:36
  • It's been some time since I last used Delphi, but is there not an escape sequence or something, such as `#$0000`? See second answer from http://stackoverflow.com/questions/302409/how-does-one-escape-characters-in-delphi-string – Morfic Oct 05 '16 at 14:39
  • You can also set the caption in code, say in `FormCreate`: `CometButton.Caption := #$2604;` – Uli Gerhardt Oct 05 '16 at 14:40
  • @MatheusOliveira What are you talking about, Delphi has good support for Unicode, and these characters can readily be used in button captions – David Heffernan Oct 05 '16 at 14:42
  • I have written a custom button control `TFontButton` for this reason - but I'm too busy to share it now. Will come back later most likely and share. – Jerry Dodge Oct 05 '16 at 18:05

2 Answers2

5

The Delphi IDE won't accept ALT key codes that high. A couple of alternatives:

  • Paste the text from somewhere else.
  • Enter the numeric code directly in the .dfm file.

As an example of the second approach, try this in your .dfm file for the button caption property:

Caption = #8592#8593#8594#8595

You also mention Green Book U+1F4D7. That is from outside the BMP, and hence encoded with a surrogate pair:

Caption = #55357#56535

My guess is that as soon as you want your glyphs to be shown in colour, or at a different size, you will find that using text makes this impossible. You are also likely to encounter fonts that don't contain glyphs for the characters you select. So you will find that using images is the most robust approach.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • It seems some characters such as (green book 128215) are not accepted by Delphi, with copy/paste. http://xahlee.info/comp/unicode_office_icons.html – Gabriel Oct 05 '16 at 14:49
  • 1
    Typical failure modes would be the font not containing a glyph for the character, or perhaps the IDE not being able to paste from outside the BMP. Encoding in the .dfm will always work in the second regard, but obviously your font must always contain a glyph. And yes, that code point is outside the BMP, takes two character elements to encode it. – David Heffernan Oct 05 '16 at 14:50
  • So that green book is `#55357#56535` – David Heffernan Oct 05 '16 at 14:57
  • Works perfectly fine for me, in XE7. Don't you believe me? Empty square just means your font doesn't have that glyph. This is why images are more reliable. – David Heffernan Oct 05 '16 at 15:01
  • Ok. I will try to change the font. Probably Tahoma is not the best font. Thanks. – Gabriel Oct 05 '16 at 15:09
  • 1
    Tahoma is ancient. But this is your problem. It looks easy now but you will get bitten at some point. .... – David Heffernan Oct 05 '16 at 15:12
3

Or, alternatively, if you had a table of the decimal values:

9731  ☃   SNOWMAN
9732  ☄   COMET
9733  ★   BLACK STAR
9734  ☆   WHITE STAR
9735  ☇   LIGHTNING
9736  ☈   THUNDERSTORM
9737  ☉   SUN
9738  ☊   ASCENDING NODE
9739  ☋   DESCENDING NODE

then you can use the keyboard as follows in Delphi.

To change the caption of Button1 to be the snowman:

  1. Press Alt+F12 to edit the form as text

  2. Press Ctrl+E to enter incremental search mode

  3. Type Button1, or as much of it as is required to locate the definition of Button1

  4. To the right of the Caption = property definition (I'm assuming VCL here) enter # followed by the relevant Unicode value, e.g. #9731

    Caption = #9731

  5. If you want text as well as the snowman, the character code goes outside quotes, so e.g.

    Caption = 'Snowman = '#9731

More info on the # syntax (which is more commonly entered in Delphi source, rather than in the text view of form files) can be found by reading about control strings, as they are actually called, in the online documentation.

Community
  • 1
  • 1
blong
  • 2,145
  • 13
  • 23
  • It strikes me that the discussion with David is suggesting you *can* encode any Unicode character using this method, if you know how to break it into the right chunks. Whether the font the button is using contains the required character, well, that's an entirely different kettle of fish. – blong Oct 05 '16 at 15:08