How to convert TStringGrid from Delphi 7 to Delphi XE

Just to test how difficult it is to convert my Delphi 7 program to Delphi XE 5, I wrote a simple Delphi 7 application - put TStringGrid in Form and added code in the create form:

procedure TFMain.FormCreate(Sender: TObject); begin With StringGrid1 do begin Cells[0,0]:='čę€'; end; end; 

(he actually wrote as Cells [0,0]: = 'ce ?? €', but I expected this). Compile, build, run, do not use Unicode. Then we opened the project again in Delphi XE 5, again changed the line to the cells [0,0]: = 'čęzhe €', compile, build, run - and not Unicode (it turned out something like čę |||)! It was weird for me. A new project is built from scratch on Delphi Xe 5 with the same code, the same TStringGrid works as expected. I know that there is a simple trick, maybe some changes in the project settings, but I can’t do it ... Maybe someone can help?

Sincerely.

+5
source share
2 answers

The default font used by Delphi 7 is MS Sans Serif. When you use this font under Unicode Delphi, the line grid control does not have to correctly draw text with this font. Many other controls correctly draw your text in this font. But for some reason, row grid control cannot do this.

When upgrading an old project to XE5, you inherit this Delphi 7 by default. When you create a new project in XE5, the default font is different, in my opinion, Tahoma, and the line grid correctly displays your Cyrillic alphabet in this font.

You can work around this problem using a different font, such as Tahoma or the Segoe user interface. You certainly do not want to use MS Sans Serif. Presenting a list in a presentation style would be another good option. Not least because it is built-in platform control.

I have to admit that I really don't understand why managing a grid of rows doesn't behave better. It would be great if someone else could shed light on this.

+6
source

As David mentions, the problem is that the font is used in your row grid. However, it is not entirely accurate to say that the default font in Delphi is MS Sans Serif . It used to be MS Sans Serif , but was changed (in Delphi 2006) to Tahoma .

You can see how a certain version of Delphi chooses the default font by checking the source of the Graphics block in the RTL source of this particular version of Delphi (since the IDE is built using this code), in particular, the InitDefFontData strong> procedure (and in older versions Delphi - record DefFontData strong>).

As of (at least) Delphi XE4 , the default Tahoma font will be replaced with any parameter to replace the font for the value specified as MS Shell Dlg 2 , as indicated in the registry:

 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\FontSubstitutes\ 

NB - from code verification in XE4 it is possible that if this key does not exist or is not available, or if there is no substitution entry for the MS Shell Dlg 2 font, then MS Sans Serif will still be used. It’s hard to say, since this behavior, when the “CLR” is defined, that should no longer be, since Delphi no longer supports .NET, and the IDE does not seem to be compiled with the CLR, but there is no way to be some just checking the code. what conditional definitions can be used when compiling the IDE.

However, whatever font is used by the IDE, and nevertheless, it selects this font, this only affects the new forms created in the IDE.

For existing forms, as in this case, the problem is not with TStringGrid as such, but rather that you created a project in the Delphi version that used the default font, which executed / did not support Unicode.

The act of opening a project in a new version of Delphi did not change the font used in your form, therefore the form saved in Delphi 7 using MS Sans Serif still uses this font when opening it in Delphi XE5 .

Then the TStringGrid element uses the MS Sans Serif font because it is the font set on the form, and the default value for the controls on the form is to use their parent control font.

i.e. This particular instance of TStringGrid uses MS Sans Serif because the form on which it is placed (still) uses MS Sans Serif .. p>

In such cases, you should change the font of the form to Tahoma or a. n. another suitable font with Unicode support.

All form controls still configured to use their parent font will then use that font. When doing this in a real application, you can find some controls with ParentFont installed by FALSE that will need to be solved individually, and even if the font settings are “inherited”, your form projects may need further work to improve the situation due to changes appearance as a result of changing the font.

Please note that even this Tahoma change was overtaken by changes in Windows itself, and if you want to use a different default font (in new forms / projects), you can find useful information here .

+1
source

Source: https://habr.com/ru/post/1205205/


All Articles