为什么我无法将类分配给其基本接口(interface)类型的变量。
考虑我们有以下内容:
IInt1 = interface
procedure Test1;
end;
IInt2 = interface(IInt1)
procedure Test2;
end;
TCustomClass = class(TInterfacedObject)
end;
TMyClass = class(TCustomClass, IInt2)
procedure Test1;
procedure Test2;
end;
var
Obj: IInt1;
begin
Obj := TMyClass.Create; // <!-- E2010 Incompatible types: 'IInt1' and 'TMyClass'
...
end;
E2010 Incompatible types: 'IInt1' and 'TMyClass'
这是编译器中的错误还是根本不允许的操作。这可以解决吗?
最佳答案
在声明中的已实现接口(interface)列表中包含 IInt1
:
TMyClass = class(TCustomClass, IInt1, IInt2)
end;
关于delphi - 无法将 TMyClass 对象分配给其基本接口(interface)类型的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9586895/