Author: Jonas Bilinkevicius
I am trying to display some results in a TRichEdit control. The text is a mixture
of Latin letters and Greek (science) letters. Obviously, I have to change the font
to 'Symbol' when I want to display the greek letter, otherwise it will be the
default font. So, how do I do that? For example how do I display in RichEdit box
the following:
RichEdit1.Lines.Add('Standard deviation /* here I want to insert the Greek letter
'sigma' */ is '+FloatToStr(sigma));
Answer:
The key is to not use Lines.Add to add the text, the Lines property is not
"formatting-aware". You do it this way:
1 { ... }2 const3 norm_font = 'Times New Roman';
4 norm_charset = DEFAULT_CHARSET;
5 symb_font = 'Symbol';
6 symb_charset = SYMBOL_CHARSET;
7 { ... }8 9 with richedit1 do10 begin11 selstart := gettextlen; {set caret to end}12 selattributes.Name := norm_font;
13 selattributes.charset := norm_charset;
14 seltext := 'Standard deviation ';
15 selattributes.Name := symb_font;
16 selattributes.charset := symb_charset;
17 seltext := 'S';
18 selattributes.Name := norm_font;
19 selattributes.charset := norm_charset;
20 seltext := ' is ' + FloatToStr(sigma);
21 { etc. }22 end;
As you see this is quite cumbersome but the alternative is even more so: constructing a *complete* rich text file (with font table!) for the text to insert and use EM_STREAMIN to get it into the text.