开发者

Constructor inheritance issue

开发者 https://www.devze.com 2023-01-09 23:51 出处:网络
I have two classes, a base class and a derived class.My base class has a constructor of this form: constructor TBaseClass.CreateFromXML(ANode: IXMLNode);

I have two classes, a base class and a derived class. My base class has a constructor of this form:

constructor TBaseClass.CreateFromXML(ANode: IXMLNode);
begin

  Create;

  //Set members from XML

end;

My开发者_高级运维 derived class has a constructor of this form:

constructor TDerivedClass.Create;
begin

   FDatabaseID = -1;

end;

My problem is that when I create an object of my derived class using the constructor from the base class [ TDerivedClass.CreateFromXML(Node); ] the Create called at the beginning of the CreateFromXML constructor is not the one from my derived class, but rather the one inherited by my base class from TObject.

Is it possible to get the base class constructor to call my derived class constructor even though it's further "down" the inheritance chain?


Try declaring a constructor Create; virtual; in TBaseClass. Don't forget to mark the "derived" constructor as override.

0

精彩评论

暂无评论...
验证码 换一张
取 消