delphi – 使用继承于TObject的“创建”构造函数
发布时间:2020-12-15 10:17:06 所属栏目:大数据 来源:网络整理
导读:应该在派生自TObject或TPersistent的类的构造函数中调用“inherited” constructor TMyObject.Create;begin inherited Create; // Delphi doc: Do not create instances of TPersistent. Use TPersistent as a base class when declaring objects that are n
应该在派生自TObject或TPersistent的类的构造函数中调用“inherited”
constructor TMyObject.Create; begin inherited Create; // Delphi doc: Do not create instances of TPersistent. Use TPersistent as a base class when declaring objects that are not components,but that need to be saved to a stream or have their properties assigned to other objects. VectorNames := TStringList.Create; Clear; end; 解决方法
是。它什么也没有,但它是无害的。我认为总是调用继承的构造函数是一致的,而不检查实际上是否存在实现。有些人会说,值得调用继承的Create,因为Embarcadero将来可能会为TObject.Create添加一个实现,但我怀疑这是真的;它会破坏不调用继承的Create的现有代码。不过,我认为这是一个好主意,只是为了一致的原因。
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |