<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, Jul 27, 2018 at 11:15 AM, Ryan Joseph <span dir="ltr"><<a href="mailto:ryan@thealchemistguild.com" target="_blank">ryan@thealchemistguild.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">I never use Free directly so I had no idea. How is that even accomplished in the language? I thought it was just a method and behaved accordingly.<br>
<br>
If it is magic then how do we call other methods on nil objects? There are times that would be handy if I could control it.</blockquote><div><br></div><div>It's not a magic, it's explicit check for the value of "Self" within a method.</div><div>Self would point to an actual instance of an object, if it's nil. Free method won't do anything.</div><div><br></div><div><div>type</div><div> TRobust = class(TObject)</div><div> public</div><div> v : Integer;</div><div> procedure RobustMethod;</div><div> end;</div><div><br></div><div>procedure TRobust.RobustMethod;</div><div>begin</div><div> if Self = nil then Exit; // remove or comment out this line to start getting AVs</div><div> v := 5;</div><div>end;</div><div><br></div><div>var</div><div> r : TRobust;</div><div>begin</div><div> r := nil;</div><div> r.RobustMethod;</div><div>end.</div></div><div><br></div><div>You could consider this a sanity check, similar to checking any other input parameters.</div><div><br></div><div>thanks,</div><div>Dmitry</div></div></div></div>