我有两个类 – 基类和继承类如下.
基类:
TAlarm = class(System.Object) private: protected: public: constructor (tag:TTagname); end;
继承类:
TAlarmMsg = class(TAlarm) public constructor (aname:string); method GetAlarmMsg:string; override; method SendMsg(msg:string); end;
构造函数:
constructor TAlarm(tag:TTagname); begin Tagname := tag; end; constructor TAlarmMsg(aname:string); begin inherited TAlarm(aname); <========Here is my problem. name := aname.tocharArray; end;
无论我使用继承的构造函数调用什么或怎么调用,我在编译源文件时都会收到以下错误消息.
– 在继承的构造函数完成之前无法访问Self.和/或
– 在基类中找不到合适的构造函数,因此需要手动调用inherited
顺便说一下,我花了半天时间研究这个问题,并在网上找到了很好的信息.到目前为止没有任何帮助.我甚至找到了直接在Delphi Prism Wikipedia(http://prismwiki.embarcadero.com/en/Constructors)上讨论构造函数的网页.
那么,你会如何正确地做到这一点?
谢谢,
解决方法
继承的构造函数(aName)应该这样做.