Grids.pas shows error in CfgSetFontValue and CfgGetFontValue
Original Reporter info from Mantis: abtaylr
-
Reporter name: Arlen B Taylor
Original Reporter info from Mantis: abtaylr
- Reporter name: Arlen B Taylor
Description:
The errors I have gotten are: grids.pas(2044,39) Error: Illegal type conversion: "TFontStyles" to "LongInt" and "grids.pas(2052,17) Error: Illegal type conversion: "LongInt" to "TFontStyles".
The two procedures begin at line 2044 and 2052 respectively. The code found in the distribution is:
procedure CfgSetFontValue(cfg: TXMLConfig; AKey: WideString; AFont: TFont);
begin
cfg.SetValue(AKey + '/name/value', AFont.Name);
cfg.SetValue(AKey + '/size/value', AFont.Size);
cfg.SetValue(AKey + '/color/value', ColorToString(AFont.Color));
cfg.SetValue(AKey + '/style/value', Integer(AFont.Style));
end;
procedure CfgGetFontValue(cfg: TXMLConfig; AKey: WideString; AFont: TFont);
begin
AFont.Name := cfg.GetValue(AKey + '/name/value', 'default');
AFont.Size := cfg.GetValue(AKey + '/size/value', 0);
AFont.Color:= StringToColor(cfg.GetValue(AKey + '/color/value', 'clWindowText'));
AFont.Style:= TFontStyles(cfg.GetValue(AKey + '/style/value', 0));
end;
The error in the first procedure arises from the line: cfg.SetValue(AKey + '/style/value', Integer(AFont.Style)); specifically the typecast of Integer shown.
The second arises from the line: AFont.Style:= TFontStyles(cfg.GetValue(AKey + '/style/value', 0)); illegal conversion from longint to TFontStyles.
TFontStyles can be found in the graphics unit at lines shown at lines 71-72:
TFontStyle = (fsBold, fsItalic, fsUnderline, fsStrikeOut);
TFontStyles = set of TFontStyle;
Steps to reproduce:
The program that I am working on uses Grids in several units. The TFontStyles are routinely used. The application that I am working on was originally written in Delphi and I am updating it. I am simply working through the errors that come up as I make the conversion. I tried a number of ways to get past the problem, so I went to the forum. Fortunately, howardpc suggested a couple of changes.
Additional information:
howardpc suggested that I change the code along the lines of :
procedure CfgSetFontValue(cfg: TXMLConfig; AKey: WideString; AFont: TFont);
var
tmp: TFontStyles;
tmpDWord: DWord absolute tmp;
begin
cfg.SetValue(AKey + '/name/value', AFont.Name);
cfg.SetValue(AKey + '/size/value', AFont.Size);
cfg.SetValue(AKey + '/color/value', ColorToString(AFont.Color));
tmp := AFont.Style;
cfg.SetValue(AKey + '/style/value', tmpDWord);
end;
procedure CfgGetFontValue(cfg: TXMLConfig; AKey: WideString; AFont: TFont);
var
tmp: DWord;
tmpStyles: TFontStyles absolute tmp;
begin
AFont.Name := cfg.GetValue(AKey + '/name/value', 'default');
AFont.Size := cfg.GetValue(AKey + '/size/value', 0);
AFont.Color:= StringToColor(cfg.GetValue(AKey + '/color/value', 'clWindowText'));
tmp := cfg.GetValue(AKey + '/style/value', 0);
AFont.Style:= tmpStyles;
end;
which worked. I suggest that the grids.pas unit of lcl be updated accordingly.
Mantis conversion info:
- Mantis ID: 35894
- OS: Kubuntu
- OS Build: 19.04
- Build: 61624
- Platform: x86_64
- Version: 2.0.2
- Monitored by: » tonyp (Tony Papadimitriou)