Why I cannot assign a class to a variable of its base interface type.
Consider we have the following:
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'
Is this a bug in the compiler or simply not an allowed action. Can this be worked around?
Include
IInt1in the list of implemented interfaces in your declaration: