应该在派生自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的现有代码。不过,我认为这是一个好主意,只是为了一致的原因。