[fpc-pascal] Out of scope method?

Sven Barth pascaldragon at googlemail.com
Thu Apr 6 11:26:25 CEST 2017


Am 06.04.2017 10:32 schrieb "Ryan Joseph" <ryan at thealchemistguild.com>:
>
> Does it exist now or has it ever been discussed that a method in TObject
could be called when an instance of an object goes out of scope? It’s
common to clean up objects in a function body after the function exits and
calling a method would be a nice way to handle this. I think c++ has such a
feature but I never heard of it in Pascal.

It's a difficult topic, cause in Object Pascal class instances are always
on the heap while in C++ they might be on the stack as well. Thus a C++
compiler will insert calls to the destructor of such an object if it goes
out of scope.

In Object Pascal currently only reference counted interfaces and (new in
trunk) records with management operators provide this feature.

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20170406/5a6e4674/attachment.html>


More information about the fpc-pascal mailing list