Discussion:
Fonts & Charsets - Strange Behaviour of Delphi
(too old to reply)
Alan Lloyd
2014-01-14 08:05:54 UTC
Permalink
I've experienced an odd behaviour of Delphi fonts with regard to charsets. I
use D3 (I know, but it works <g>). It would be interesting to know if it
also happens with later Ds.

I use a TStringGrid and want to prefix a displayed string with a tick for
some data condition, so to display the tick I code in ???DrawCell() :

if {some condition} then begin
MyStringGrid.Canvas.Font.Name := 'Monotype Sorts'; // tick character
font
MyStringGrid.Canvas.Font.TextOut(ARect.Left, ARect.Top + 4, '4'); // '4'
== tick character
MyStringGrid.Canvas.Font.Name := 'Arial'; // revert to normal font
end;
MyStringGrid.Canvas.TextOut . . . // other text.

This works fine - provided I don't select a non-parent font for my
stringgrid. In that case the display is a '4' instead of a tick.

The reason apparently (by inspecting the form in "View as text") is that
when a non-parent font is selected, the Font.Charset is declareded in the
.dfm as ANSI_CHARSET, and this is maintained when the Font.Name is declared
as Monotype Sorts in my ???DrawCell code. Hence the character 4 is displayed
rather than the tick. The Font.Charset is not declared in the .dfm when
ParentFont is true.

The solution is either to code the Font.Charset (in addition to the
Font.Name) as SYMBOL_CHARSET when changing the font, and revert to
ANSI_CHARSET when the font name reverts.

Alternatively after selecting the non-parent font in the Object Iinspector,
then open the form with "View as Text" and change the stringgrid charset
definition to DEFAULT_CHARSET .. .

. . . Or code the stringgrid.Canvas.Font.Charset as DEFAULT_CHARSET at some
initialisation point in the program code.

Comments anyone ?

Alan Lloyd
Hans-Peter Diettrich
2014-01-14 09:38:52 UTC
Permalink
Post by Alan Lloyd
I've experienced an odd behaviour of Delphi fonts with regard to charsets. I
use D3 (I know, but it works <g>). It would be interesting to know if it
also happens with later Ds.
Charset problems exist in all Delphi Ansi versions. Delphi 2009 ff. use
Unicode, where you must provide the correct Unicode character for the tick.

DoDi

Loading...