[Pkg-pascal-devel] Bug#813718: Bug#813718: mricron: FTBFS: dialogsx.pas(77, 14) Error: (4054) Illegal type conversion: "TMsgDlgButtons" to "TMsgDlgButtons"
Michalis Kamburelis
michalis.kambi at gmail.com
Sat Feb 6 14:42:02 UTC 2016
> I can't see where the dialogs unit is getting the TMsgDlgButtons method
> or function or procedure or whatever it is called in Pascal from.
Short story: the patch is attached, it should help:)
Longer explanation:
1. TMsgDlgButtons is a "type". It's a set (which is like a type-safe
bitfield in Pascal). Writing "Dialogs.TMsgDlgButtons" means "take
TMsgDlgButtons type from Dialogs unit, not from any other unit that
may define the same name" --- that's how you deal with multiple used
units having the same identifier in Pascal.
2. What happens in this code is a little dirty, as mricron code
defines it's own type "TMsgDlgButtons", with the *exact* same memory
layout as standard "TMsgDlgButtons" type in "Dialogs" unit. "Dialogs"
unit is part of the Lazarus library (LCL). Then the line
lButtons:= Dialogs.TMsgDlgButtons(Buttons);
converts one type to another. The dirtyness here is that such typecast
avoids any type checks, it just assumes that memory layout of both
"TMsgDlgButtons" types matches, and that the programmer knows what
(s)he is doing:)
3. To make it a little confusing, type names are the same, so you need
to be aware how compiler resolves them, and some error messages become
unclear. This message from FPC:
Illegal type conversion: "TMsgDlgButtons" to "TMsgDlgButtons"
actually means that we cannot convert "TMsgDlgButtons as defined in
unit dialogsx" to "TMsgDlgButtons as defined in unit Dialogs".
Possibly FPC checks got stricter? Which would be a good thing here ---
this code is indeed dangerous, it's good that it's prohibited, IMHO.
In fact, Lazarus Dialogs.TMsgDlgButtons type did change (there's a new
enum mbClose), it only accidentally didn't change the memory layout of
TMsgDlgButtons (as mbClose was added at the end).
4. The attached patch just does the type conversion the long (but safe) way.
Regards,
Michalis
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dialogsx.patch
Type: text/x-diff
Size: 1707 bytes
Desc: not available
URL: <http://lists.alioth.debian.org/pipermail/pkg-pascal-devel/attachments/20160206/e52cecad/attachment-0001.patch>
More information about the Pkg-pascal-devel
mailing list