Delphi 2006 introduced operator overloading, which was later fixed in Delphi 2007. This applies to Delphi 2007.
Why the following does not compile:
type
TFirstRec = record
end;
type
TSecondRec = record
end;
type
TThirdRec = record
class operator Add(_a: TFirstRec; _b: TSecondRec): TThirdRec;
end;
class operator TThirdRec.Add(_a: TFirstRec; _b: TSecondRec): TThirdRec;
begin
end;
var
a: TFirstRec;
b: TSecondRec;
c: TThirdRec;
begin
c := a + b;
end.
Since I declared a statement that adds two operands a of type TFirstRec and b of type TSecondRec, which results in TThirdRec, I would expect this to compile.
(If you need something less abstract, think about TMyDate, TMyTime, and TMyDateTime.)
source
share