Missing warning?
type
TMyClass = class abstract (TObject)
// Lots of methods, but none of them abstract;
end;
TMyImplementedClass = class(TMyClass)
// Overrides some of the parent methods and adds new ones
end;
…
var
TFoo: TMyClass;
begin
TFoo := TMyClass.Create; *// WHAT!? No Warnings!?*
The XE2 to XE7 documentation states…
http://docwiki.embarcadero.com/RADStudio/XE7/en/Classes_and_Objects
states “Note: Delphi allows instantiating a class declared abstract, for backward compatibility, but this feature should not be used anymore.” – which is all dandy, but not issuing a warning for such use, that seems wrong to me.
Interestingly, the XE version is different…
http://docwiki.embarcadero.com/RADStudio/XE/en/Classes_and_Objects
and says “If a class is marked abstract, then it cannot be instantiated directly using the Create constructor. “
When did they introduce this keyword – and why did they not stick with the XE design? Go figure…
Is there a QP or QC for this?
Calling Roman Yankovsky … 😀
David Millington Some things are fundamental, and need attention in the compiler. This would seem to be one of those. Really, this should be cause for embarrassment.
Bill Meyer True. But I’m sure Roman is looking out for useful checks he can add. Plus, he adds things to FixInsight faster than we get new compiler releases :p
Oh yes. Been there. Fell in the trap with my eyes wide open (:
Only different between XE and XE2 to XE7 is: The documentation was updated. You are still able to instatiate a abstact class in XE 🙁
Say what? There is a good thing in XE 😉
Fabian S. Biehn – Noted.
Anyone know when class abstract was added to the language?
David Millington Yes, I am sure Roman Yankovsky is likely to be faster. Sad.
Lars Fosdal From http://www.tindex.net/Language/abstract.html, D2006
http://qc.embarcadero.com/wc/qcmain.aspx?d=122525
http://qc.embarcadero.com/wc/qcmain.aspx?d=24662
Imo leaving wrong behavior in the name of backwards compatibility and just change doc is not the right decision. If anyone creates an abstract class in his code then he has to fix his broken code after an update, period!
Stefan Glienke – IMO, it needs to at least output a warning. Isn’t the whole idea of an abstract class, that it simply is a “template” for actual implementations to inherit from?
Added
https://quality.embarcadero.com/browse/RSP-10235
Lars Fosdal You got my vote!