Delphi 2006 introduced operator overloading which was then bugfixed in Delphi 2007. This is about Delphi 2007.
Why does the following not compile:
type
TFirstRec = record
// some stuff
end;
type
TSecondRec = record
// some stuff
end;
type
TThirdRec = record
// some stuff
class operator Add(_a: TFirstRec; _b: TSecondRec): TThirdRec;
end;
class operator TThirdRec.Add(_a: TFirstRec; _b: TSecondRec): TThirdRec;
begin
// code to initialize Result from the values of _a and _b
end;
var
a: TFirstRec;
b: TSecondRec;
c: TThirdRec;
begin
// initialize a and b
c := a + b; // <== compile error: "Operator not applicable to this operand type"
end.
Since I have declared an operator that adds two operands a of type TFirstRec and b of type TSecondRec resulting in a TThirdRec, I would have expected this to compile.
(If you need something less abstract, think of TMyDate, TMyTime and TMyDateTime.)