So my brain is drawing a blank here for some reason... why doesn't the following compile?

So my brain is drawing a blank here for some reason... why doesn't the following compile?


type
  TProc = reference to procedure;

  IWidget = interface
    procedure Explode;
  end;
  TWidget = class(TInterfacedObject, IWidget)
    procedure Explode;
  end;
{ TWidget }
procedure TWidget.Explode;
begin
  WriteLn('Boom');
end;
var
  w: IWidget;
  p: TProc;
begin
  w := TWidget.Create;
  p := w.Explode;  // E2010 Incompatible types: 'TProc' and 'procedure, untyped pointer or untyped parameter'
  p();
end.

If I change the type of w to be TWidget, ie a regular object instance, it works as expected. What makes interfaces special in this case?

Using D10 Update 1 if it makes a difference.

Comments