<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">2018-08-18 20:26 GMT+02:00 Marcos Douglas B. Santos <span dir="ltr"><<a href="mailto:md@delfire.net" target="_blank">md@delfire.net</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="gmail-">On Sat, Aug 18, 2018 at 2:04 PM, Ryan Joseph <<a href="mailto:ryan@thealchemistguild.com">ryan@thealchemistguild.com</a>> wrote:<br>
><br>
> How does TAutoFree in mORMot work? Never heard of this.<br>
<br>
</span>See <a href="http://blog.synopse.info/post/2014/11/14/Automatic-TSQLRecord-memory-handling" rel="noreferrer" target="_blank">http://blog.synopse.info/post/<wbr>2014/11/14/Automatic-<wbr>TSQLRecord-memory-handling</a></blockquote><div><br></div><div>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:</div><div><br></div><div><span style="font-size:12.8px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">=== code begin ===</span>
<br></div><div><div>function NewMaleBaby(Client: TSQLRest; const Name,Address: RawUTF8): TID;</div><div>var Baby: TSQLBaby; </div><div>begin</div><div> with TSQLBaby.AutoFree(Baby) do begin</div><div> Baby.Name := Name;</div><div> Baby.Address := Address;</div><div> Baby.BirthDate := Date;</div><div> Baby.Sex := sMale;</div><div> result := Client.Add(Baby);</div><div> end;</div><div>end;</div></div><div>
<span style="font-size:12.8px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">=== code end ===</span>
<br></div><div><br></div><div>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.<br></div><div><br></div></div>-- <br><div class="gmail_signature"><div dir="ltr"><div>Best regards,<br>Maciej Izak</div></div></div>
</div></div>