View Issue Details

IDProjectCategoryView StatusLast Update
0035894LazarusLCLpublic2019-11-04 19:16
ReporterArlen B TaylorAssigned ToJesus Reyes 
PrioritynormalSeverityminorReproducibilityalways
Status feedbackResolutionopen 
Platformx86_64OSKubuntuOS Version19.04
Product Version2.0.2Product Build61624 
Target VersionFixed in Version 
Summary0035894: Grids.pas shows error in CfgSetFontValue and CfgGetFontValue
DescriptionThe 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 ReproduceThe 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 Informationhowardpc 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.
TagsNo tags attached.
Fixed in Revision
LazTarget-
WidgetsetGTK 2
Attached Files

Activities

Jesus Reyes

2019-07-27 03:02

developer   ~0117426

This can be done, however the fact that it has been working for years, requires or otherwise claims for an explanation, what is your FPC version (or revision), and what are your compile options.

wp

2019-07-27 12:19

developer   ~0117431

Last edited: 2019-07-27 13:33

View 2 revisions

I cannot reproduce such a compilation error:

(1) Laz 2.0.2 / fpc 3.0.4, 64 bit - Win 10 / 64 bit
(2) Laz trunk r61628 / fpc trunk r42503, 32 bit - Win 10 / 64 bit
(3) Laz fixes r61628 / fpc fixes r42503, 32 bit - Win 10 / 64 bit
(4) Laz trunk r61628 / fpc 3.0.4 / 64 bit - Ubuntu 18.04, gtk2, 64 bit.

In each case, the IDE was compiled with "Tools" > "Configure Build Lazarus" > "Normal IDE". No compilation error (standard "out-of-the-box" settings).

Repeated with profile "IDE with debugger information" (standard "out-of-the-box" settings). No compilation errors, too, except for (2) which crashes due to "internal error 200510032" in unit SynEditHighLigherXMLBase.pas - not related to this report).

Tony Papadimitriou

2019-11-04 18:58

reporter   ~0119057

Last edited: 2019-11-04 19:16

View 4 revisions

I've been having the same issue with the last few versions of Lazarus (I think starting from 1.8.2) under both Win32/64.
If I install an older Lazarus, it works again.
The suggested work-around compiled OK.

However, I now get a similar error elsewhere:
win32callback.inc(1386,20) Error: Illegal type conversion: "LongWord" to "TOwnerDrawState"

Oh, well...

Issue History

Date Modified Username Field Change
2019-07-27 02:29 Arlen B Taylor New Issue
2019-07-27 03:02 Jesus Reyes Note Added: 0117426
2019-07-27 03:04 Jesus Reyes Assigned To => Jesus Reyes
2019-07-27 03:04 Jesus Reyes Status new => feedback
2019-07-27 03:04 Jesus Reyes LazTarget => -
2019-07-27 12:19 wp Note Added: 0117431
2019-07-27 13:33 wp Note Edited: 0117431 View Revisions
2019-11-04 18:58 Tony Papadimitriou Note Added: 0119057
2019-11-04 19:01 Tony Papadimitriou Note Edited: 0119057 View Revisions
2019-11-04 19:01 Tony Papadimitriou Note Edited: 0119057 View Revisions
2019-11-04 19:16 Tony Papadimitriou Note Edited: 0119057 View Revisions