[fpc-pascal] Constructors & Destructors 101

Bart bartjunk64 at gmail.com
Fri Apr 3 16:21:46 CEST 2009


On 4/3/09, Jonas Maebe <jonas.maebe at elis.ugent.be> wrote:
>  I think what is meant, is that if you create a direct subclass of TObject,
> there is no need to call TObject's create constructor (e.g., via "inherited
> create;") from your own constructors. It doesn't hurt if you do it of
> course, and may be good practice to account for future situations where the
> parent class may change.

I often wondered abou that.

So if i understand correctly:

Say I have

Type
  TFoo = class;
  private
    fSomeField: Integer;
  public
    constructor Create;
  end;

then

constructor  TFoo.Create
begin
  Inherited Create;
  fSomeField := -1;
end;

would in essence be equal to

constructor  TFoo.Create
begin
  fSomeField := -1;
end;

Since TOblect.Create "does nothing".

Bart



More information about the fpc-pascal mailing list