RobertFrank
RobertFrank

Reputation: 7394

How to display Greek symbols in a TMenuOption

In Delphi 2010, I want to display the Greek symbols (alpha, beta, etc.) in TMenuOption and other types of VCL controls.

Assigning

   TEdit.Text or TMenuItem.Caption := 'Hydrogen ' + chr(945)  + ' More Text'

seems to work fine.

I'm worried that this might won't work on all machines. TEdit has a font property, TMenuItem doesn't, so I'm guessing it uses some default system font.

Should chr(945) always show as the Greek alpha character regardless of font? If not, is there some way for me to assure that the chr(945) always appears on the screen as the alpha character other than hard-wiring the font (which would be tough to do for the system font...)

TIA

Upvotes: 2

Views: 1848

Answers (2)

Toon Krijthe
Toon Krijthe

Reputation: 53366

You can also use constants. The source files are unicode too so you can add any kind of constant. Just remember to save the source as unicode.

const
  alpha = 'α';
  beta  = 'β';
  gamma = 'γ';

Upvotes: 3

GolezTrol
GolezTrol

Reputation: 116110

Since Delphi 2010 is unicode, chr(945) always point to the same character, in this case Greek Alpha. This character will display correctly if the font that is used to draw the menu item contains that character. There is no risk of another character being drawn, except maybe for the question mark, which is usually used by Windows if a font doesn't contain a specific character.

Most Windows fonts do contain common unicode characters (including Greek). The user might however be able to select a different font that doesn't. You can draw the menu yourself using a different font that is installed on the system, but this might be an awful lot of work for something that will normally work out of the box.

Upvotes: 1

Related Questions