2018-08-18 20:26 GMT+02:00 Marcos Douglas B. Santos <m...@delfire.net>:

> On Sat, Aug 18, 2018 at 2:04 PM, Ryan Joseph <r...@thealchemistguild.com>
> wrote:
> >
> > How does TAutoFree in mORMot work? Never heard of this.
>
> See http://blog.synopse.info/post/2014/11/14/Automatic-
> TSQLRecord-memory-handling


worth to note that in FPC you additionally need to use "with ... do" (or
use local variable IAutoFree), otherwise interface will be release
immediately and code will be broken. The example in blog needs to be
corrected:

=== code begin ===
function NewMaleBaby(Client: TSQLRest; const Name,Address: RawUTF8): TID;
var Baby: TSQLBaby;
begin
  with TSQLBaby.AutoFree(Baby) do begin
    Baby.Name := Name;
    Baby.Address := Address;
    Baby.BirthDate := Date;
    Baby.Sex := sMale;
    result := Client.Add(Baby);
  end;
end;
=== code end ===

or you need to wait for {$MODESWITCH SCOPEDINTERFACEDESTROY} in NewPascal
to use examples AS-IS (with SCOPEDINTERFACEDESTROY on). To be honest I
forgot to send the patch with SCOPEDINTERFACEDESTROY to FPC when I had
occasion/access to FPC trunk ^^ - anyway I was the only one who want this
in the FPC core team for Delphi compatibility (and for large legacy
projects where is really hard to adjust code which depends on
SCOPEDINTERFACEDESTROY)... FPC core team said that this behavior of Delphi
is not documented and not COM compatible (or is undefined in COM - I don't
remember). Also there is some mystery example for large methods when Delphi
is able to break the rule and such interface is released earlier (but no
one was able to provide this example) - I was also trying without success,
so SCOPEDINTERFACEDESTROY seems really Delphi compatible.

-- 
Best regards,
Maciej Izak
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to