In Delphi XE it'll EAbstractError on the selected line:

In Delphi XE it'll EAbstractError on the selected line:

[code]
program Test071;

{$APPTYPE CONSOLE}

uses
  SysUtils;

type
  TBaseClass = class
  public
    procedure Test; virtual; abstract;
  end;

  TMyClass = class(TBaseClass)
  public
    procedure Test; override;
  end;

{ TMyClass }

procedure TMyClass.Test;
begin
  inherited;
  inherited Test; // <--- EAbstractError here :(
end;

{ TestProc }

procedure TestProc;
var
  LMyClass: TMyClass;
begin
  LMyClass := TMyClass.Create;
  try
    LMyClass.Test;
  finally
    LMyClass.Free;
  end;
end;

begin
  try
    TestProc;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.
[/code]

The 1st line will not compiled but the second yes (simply jumping to System._AbstractError);

Is it fixed in XE6? :)

Comments

  1. I would've thought it should be the right thing to do, hence I hope it's not "fixed".

    A

    ReplyDelete
  2. That has been that way since D5 (maybe earlier) and I agree with the outcome (and Andrea)

    ReplyDelete
  3. Thank You!

    I just think it's a bit confusing for me, that the first line is not compiled, but the second yes, cause I think, both source code line have the same meaning and none of them should "process" the Delphi compiler into the final machine code.

    ReplyDelete
  4. The "inherited;" is used by the IDE if you implement an event handler in a form that doesn't inherit from TForm but from another form.
    So it could be possible that the idea behind this difference is that the compiler helps the IDE to make things easier - No base class check, just writing "inherited;".

    ReplyDelete

Post a Comment