delphi – 使用继承于TObject的“创建”构造函数

前端之家收集整理的这篇文章主要介绍了delphi – 使用继承于TObject的“创建”构造函数前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
应该在派生自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的现有代码。不过,我认为这是一个好主意,只是为了一致的原因。

猜你在找的Delphi相关文章