If I try to compile the following code I got an error message "E2010 Incompatible types: 'Extended' and 'TMyRec'" for the last line (E := R):
type
TMyRec = record
class operator Implicit(Rec: TMyRec) : Integer;
class operator Implicit(Rec: TMyRec) : Extended;
end;
class operator TMyRec.Implicit(Rec: TMyRec) : Integer;
begin
Result := 1;
end;
class operator TMyRec.Implicit(Rec: TMyRec) : Extended;
begin
Result := 1;
end;
var
R : TMyRec;
B : Byte;
E : Extended;
begin
B := R; //this is OK
E := R; //E2010 Incompatible types: 'Extended' and 'TMyRec'
end.
I asked a friend to try to compile it in XE - the compilation succeeded. So is this a bug in BDS2006? Is there any way to solve this problem?
This is indeed a compiler defect. The only way to fix it is to upgrade to a version of the compiler that resolves the defect. If you cannot do that you'll just need to write your code in a different way.
FWIW, in my view, it is invariably a mistake to use
Extended. This type is non-standard and only exists on x86. At some point in the future if you move to x64 you will find thatExtendedis mapped ontoDouble. Furthermore, the alignment of the type leads to poor memory access performance and programs that store data asExtendedrather thanDoubletend to be noticeably slower.