[fpc-pascal] Managed properties idea
hnb.code at gmail.com
Mon Oct 9 20:54:09 CEST 2017
2017-10-09 14:43 GMT+02:00 Marcos Douglas B. Santos <md at delfire.net>:
> This TAutoFree just "put" the "finally" and call .Free for an array of
> objects or does it something else?
> Could you send the link of the implementation?
"One" and "Several" returns IAutoFree interface. Implementation of that
interface contains TObject/array of TObject fields. TObject/array of
TObject is freed when interface goes out of the scope (so yes you can omit
"finally", the "Free" call for allocated objects by TAutoFree is
please note that FPC behaves different than Delphi, so you can't do the
TAutoFree.One(o, TFoo.Create); // for such code interface is released at
this place in FPC
WriteLn(o.SomeMethod); // AV i FPC
end; // in Delphi returned interface by TAutoFree.One is released here
so correct code for FPC is:
with TAutoFree.One(o, TFoo.Create) do
o.SomeProperty := 123;
Maybe at some point the first code listing will be valid in FPC too (by
usage of new modeswitch SCOPEDINTERFACEDESTROY).
implementation of TAutoFree can be found here:
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the fpc-pascal