<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div><div><<Paraphrasing Graeme’s and other’s previous emails. Please refer to the posted emails and all the responses if you need to.>></div></div><div><br class=""><blockquote type="cite" class="">I use Class and Object data types frequently in my code. I like the fact<br class="">that Object data types can be used without first instantiating an<br class="">instance and it gets freed automatically.</blockquote><blockquote type="cite" class=""><font color="#000000" class=""><snip></font></blockquote><blockquote type="cite" class="">It has to be said that for more complex "objects" I always use a Class<br class="">type though. Also, Delphi compatibility (or their lack of Object type<br class="">support) is of no concern to me.</blockquote><blockquote type="cite" class=""><<font color="#000000" class="">snip</font>></blockquote><blockquote type="cite" class="">Are there pros or cons to either?</blockquote><blockquote type="cite" class=""><br class=""></blockquote>When I first decided to explore OOP in FPC, I (as well as most others) discovered that FPC supported two different Object models and wondered the same.  In those days I had some free time to explore and ended up creating a Free Pascal Wiki article : </div><div><br class=""></div><div><a href="http://wiki.freepascal.org/Programming_Using_Objects" class="">http://wiki.freepascal.org/Programming_Using_Objects</a> </div><div><a href="http://wiki.freepascal.org/Programming_Using_Objects" class="">Programming Using Objects - Free Pascal wiki</a></div><div><br class=""></div><div>Unfortunately I ran out of time and never got to the Class based version.  I started out liking the Object model for exactly the same reason you state, due to the simpler overhead of not having to “worry” as much about memory leak and initialization coding.  In short, I abandoned the Object model since most of the FPC support was for the Class model and mixing Class and Object models in the same code base can get confusing resulting in more types of bugs and increased time spent maintaining stuff.  Also, there are other (sometimes subtle) differences in how the Object and Class models are implemented.  For production code, my opinion is to avoid mixing models.</div><div><br class=""></div><div>There was an offshoot discussion about reference vs. value types and your original comment above seems to be a common general consensus that one gravitates towards value types for simple structures and class (reference) types for more complex information where “identity” aspects are considered.  About two years ago, I decided I needed to learn another language and started exploring Ruby and Python.  About 3 months after surveying those languages, Apple unveiled Swift and I decided I would bite the bullet and delve into it.  If anyone wants to hear summaries of what I have learned, I would be happy to take a discussion over to FPC-other or private email.  </div><div><br class=""></div><div>I mention my extended Swift dalliance here because one of the major internal dichotomies in the Swift language itself is reference vs value languages constructs superimposed with mutable and immutable keywords.  You may find the following article helpful which discusses how to determine when to use value vs. reference types.  It uses Swift examples but the analysis is generic.</div><div><br class=""></div><div><h1 class="page-title" style="box-sizing: border-box; margin-bottom: 0.5rem; line-height: 1.25; color: rgb(48, 48, 48); text-rendering: optimizelegibility; font-size: 2rem; margin-top: 0px; font-family: 'PT Sans', Helvetica, Arial, sans-serif;">Should I use a Swift struct or a class?</h1><div class=""><a href="http://faq.sealedabstract.com/structs_or_classes/" class="">http://faq.sealedabstract.com/structs_or_classes/</a></div><div class=""><br class=""></div><div class="">-Richard</div><div class=""><br class=""></div></div></body></html>