如何从Delphi Phrism中的继承类中正确调用基类构造函数?
发布时间:2020-12-15 04:13:07 所属栏目:大数据 来源:网络整理
导读:我有两个类 – 基类和继承类如下. 基类: TAlarm = class(System.Object)private:protected:public: constructor (tag:TTagname);end; 继承类: TAlarmMsg = class(TAlarm) public constructor (aname:string); method GetAlarmMsg:string; override; method
我有两个类 – 基类和继承类如下.
基类: 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.和/或 顺便说一下,我花了半天时间研究这个问题,并在网上找到了很好的信息.到目前为止没有任何帮助.我甚至找到了直接在Delphi Prism Wikipedia(http://prismwiki.embarcadero.com/en/Constructors)上讨论构造函数的网页. 那么,你会如何正确地做到这一点? 解决方法
继承的构造函数(aName)应该这样做.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |