我在 Delphi 2006 中对记录使用运算符重载。(请不要告诉我不要回答这个问题。)
我有两种记录类型,其中隐式运算符重载。它们都只在模块的实现中,不通过接口暴露。
我的问题是,既然它们是相互依赖的,我不知道如何将第二种类型的声明转发给编译器。我知道如何处理函数、过程和类,但不知道如何处理记录。
这是我正在尝试做的一个简化示例:
implementation
type
TMyRec1 = record
Field1 : Integer;
class operator Implicit(a: TMyRec2): TMyRec1; // <---- Undeclared Identifier here.
end;
TMyRec2 = record
Field2: Integer;
class operator Implicit(a: TMyRec1): TMyRec2;
end;
class operator TMyRec1.Implicit(a:TMyRec2): TMyRec1;
begin
Result.Field1 := a.Field2;
end;
class operator TMyRec2.Implicit(a:TMyRec2): TMyRec2;
begin
Result.Field2 := a.Field1;
end;