Am 25.04.2022 um 17:30 schrieb Michael Van Canneyt via fpc-pascal:


On Mon, 25 Apr 2022, Thomas Kurz via fpc-pascal wrote:

I cannot remember why, but a long time ago when learning Delphi 5 or 6, I
have learned not to call the destructor from within any method of the
class, only from outside.  If this is no longer true nowadays (or maybe,
has never been true before), I'd like to use this solution.

If it is the last thing you do in the method, there is no problem.

Note that "Free" itself is a method that calls Destroy (the actual
destructor), so the advice you got was strange to say the least :-)

To be precise: as long as you don't access Self after a Free (this includes calling virtual methods, but not non-virtual ones) this is no problem. This has been this way in both FPC and Delphi since the beginning of TObject.

Regards,
Sven
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to