For starters, since class constructors cannot be virtual (it makes no sense to be virtual), you need to remove the virtual and override keywords in order to compile your code.
Class constructors are commonly used to initialize vars classes. Classes of classes usually should be initialized once and once. If you could call inherited as you suggest in the question, then TBaseClass.ClassCreate will be called several times when in fact it needs to be called exactly once.
While you can write inherited in the constructor of the class and the code will compile, the compiler simply ignores it.
program ClassConstructors; {$APPTYPE CONSOLE} uses SysUtils; var Count: Integer; type TBaseclass = class public class constructor ClassCreate; end; TOtherClass = class(TBaseClass) public class constructor ClassCreate; end; class constructor TBaseClass.ClassCreate; begin inc(Count); end; class constructor TotherClass.ClassCreate; begin inherited; end; begin TBaseClass.Create.Free; TOtherClass.Create.Free; Writeln(Count);//outputs 1 Readln; end.
Note that, of course, both class constructors are executed.
David heffernan
source share