[fpc-devel] Initialize/Finalize management operators and Default intrinsic

Sven Barth pascaldragon at googlemail.com
Sun Apr 10 23:54:42 CEST 2016


Am 10.04.2016 21:34 schrieb "Maciej Izak" <hnb.code at gmail.com>:
>
> Hi,
>
> Is right to call Initialize operator for Default(TFoo) where TFoo is
record with management operators? IMO the right direction is to keep "meta
record instance" in place where TFoo is declared and call Initialize
operator before "class constructors" and before initialize section (TFoo
class var instance might be used inside class constructor).

There are two things to differentiate:
- Default() used in global variables
- Default() used locally

The latter creates a local variable and basically FillChar()s it while the
former creates a zero initialized global variable.
(Thinking about this I could use the global variable approach also for
local uses of Default(), with the only special case being generics, but
that's another topic...)

So in the local case you'd need to add an Initialize() after the FillChar()
call (if I haven't done that already).
In the global case you'd need to add the corresponding calls to the
implicit initialization function which is called before the unit's
initialization section. Currently class constructors are called before
that, but that's not good (though the implications are worse with the
finalization) and is subject to change. Please don't work around it
although right now it would work incorrectly for such variables used in
class constructors.

Note: and don't forget the finalization ;)

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20160410/ad667ed4/attachment.html>


More information about the fpc-devel mailing list