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? :)
[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? :)
I would've thought it should be the right thing to do, hence I hope it's not "fixed".
ReplyDeleteA
That has been that way since D5 (maybe earlier) and I agree with the outcome (and Andrea)
ReplyDeleteThank You!
ReplyDeleteI 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.
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.
ReplyDeleteSo 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;".
I think the answer is here
ReplyDeletehttp://hallvards.blogspot.tw/2006/03/virtual-methods-and-inherited.html?m=1
something like Andreas Hausladen said above.
What Sam Shaw said :)
ReplyDelete