[fpc-pascal]create and destroy

Michael Van Canneyt michael.vancanneyt at wisa.be
Mon Dec 17 11:32:05 CET 2001


On Mon, 17 Dec 2001, Shifted Soul wrote:

> Hello, I have two small questions, if you can give me a yes or no only.
> Q1 : Can I call a method from the constructor of the same class. Example
> :
> TSample = CLASS
>                   PUBLIC
>                   CONSTRUCTOR Create;
>                   DESTRUCTOR Destroy;Override;
>                   PROCEDURE a;
> END;
>
> CONSTRUCTOR TSample.Create;
> BEGIN
>    a;
> END;

Yes you can.

>
> Q2 : I know that the standard is to override the "destroy" destructor
> and to use the free method to dstroy the object. I know also that the
> standard "destroy" don't have any parameter. But I want to have a
> destructor with parameters, can I do it without being out of standard,
> don't tell me that I can call the destructor directly, because I gave a
> sample a time ago with a direct call to the destructor which made a
> great deal about standards, so I won't to make more troubles in this
> mailing list.

You can perfectly do that, BUT:
- You cannot use the Free method (nowhere).
- Your top-level class destructor must always call 'Destroy' so
  TObject.Destroy is called as the last destructor.

Michael.





More information about the fpc-pascal mailing list