<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><meta name=Generator content="Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
{font-family:Courier;
panose-1:2 7 4 9 2 2 5 2 4 4;}
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Consolas;
panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;
color:black;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
pre
{mso-style-priority:99;
mso-style-link:"HTML Preformatted Char";
margin:0in;
margin-bottom:.0001pt;
font-size:10.0pt;
font-family:"Courier New";
color:black;}
p.msonormal0, li.msonormal0, div.msonormal0
{mso-style-name:msonormal;
mso-margin-top-alt:auto;
margin-right:0in;
mso-margin-bottom-alt:auto;
margin-left:0in;
font-size:11.0pt;
font-family:"Calibri",sans-serif;
color:black;}
span.HTMLPreformattedChar
{mso-style-name:"HTML Preformatted Char";
mso-style-priority:99;
mso-style-link:"HTML Preformatted";
font-family:Consolas;
color:black;}
span.kw
{mso-style-name:kw;}
span.sym
{mso-style-name:sym;}
span.cmt
{mso-style-name:cmt;}
span.str
{mso-style-name:str;}
span.EmailStyle25
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body bgcolor=white lang=EN-US link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span style='color:windowtext'>I don’t seem to have FreeThenNil I’m using FPC 3.0.4RC1 I don’t use Lazarus.. maybe it’s a Lazarus thing… or maybe it’s in a different unit <o:p></o:p></span></p><p class=MsoNormal><span style='color:windowtext'><o:p> </o:p></span></p><p class=MsoNormal><span style='color:windowtext'>plotdraw.pax.pas(20,7) Error: Identifier not found "FreeThenNil" <o:p></o:p></span></p><p class=MsoNormal><span style='color:windowtext'><o:p> </o:p></span></p><div><p class=MsoNormal><span style='color:windowtext'>James<o:p></o:p></span></p></div><p class=MsoNormal><span style='color:windowtext'><o:p> </o:p></span></p><div><div style='border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in'><p class=MsoNormal><b><span style='color:windowtext'>From:</span></b><span style='color:windowtext'> fpc-pascal <fpc-pascal-bounces@lists.freepascal.org> <b>On Behalf Of </b>Giuliano Colla<br><b>Sent:</b> Monday, May 20, 2019 6:01 PM<br><b>To:</b> fpc-pascal@lists.freepascal.org<br><b>Subject:</b> Re: [fpc-pascal] Checking if a TStringList already exists<o:p></o:p></span></p></div></div><p class=MsoNormal><o:p> </o:p></p><p>Il 20/05/2019 15:23, James Richters ha scritto:<o:p></o:p></p><blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><pre>Thank you very much for the explanation and examples of this! I am glad you pointed out the FreeAndNill() function, I will defiantly be needing that.<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>James<o:p></o:p></pre></blockquote><p class=MsoNormal><br>Then you might also appreciate the function Assigned. Assigned(P) returns true if P is non-nil, and false if P is Nil. Nothing fancy, just making the code more readable.<br><br>From fpc documentation:<br><br><o:p></o:p></p><blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><pre style='font-variant-ligatures: normal;font-variant-caps: normal;orphans: 2;text-align:start;widows: 2;-webkit-text-stroke-width: 0px;text-decoration-style: initial;text-decoration-color: initial;word-spacing:0px'><span class=kw><b><span style='font-size:10.5pt;font-family:Courier'>Program</span></b></span><span style='font-size:10.5pt;font-family:Courier'> Example96</span><span class=sym><span style='font-size:10.5pt;font-family:Courier;color:darkred'>;</span></span><span style='font-size:10.5pt;font-family:Courier'><o:p></o:p></span></pre><pre><span style='font-size:10.5pt;font-family:Courier'><o:p> </o:p></span></pre><pre><span class=cmt><i><span style='font-size:10.5pt;font-family:Courier;color:darkcyan'>{ Program to demonstrate the Assigned function. }</span></i></span><span style='font-size:10.5pt;font-family:Courier'><o:p></o:p></span></pre><pre><span style='font-size:10.5pt;font-family:Courier'><o:p> </o:p></span></pre><pre><span class=kw><b><span style='font-size:10.5pt;font-family:Courier'>Var</span></b></span><span style='font-size:10.5pt;font-family:Courier'> P </span><span class=sym><span style='font-size:10.5pt;font-family:Courier;color:darkred'>:</span></span><span style='font-size:10.5pt;font-family:Courier'> Pointer</span><span class=sym><span style='font-size:10.5pt;font-family:Courier;color:darkred'>;</span></span><span style='font-size:10.5pt;font-family:Courier'><o:p></o:p></span></pre><pre><span style='font-size:10.5pt;font-family:Courier'><o:p> </o:p></span></pre><pre><span class=kw><b><span style='font-size:10.5pt;font-family:Courier'>begin</span></b></span><span style='font-size:10.5pt;font-family:Courier'><o:p></o:p></span></pre><pre><span style='font-size:10.5pt;font-family:Courier'> <span class=kw><b>If</b></span> <span class=kw><b>Not</b></span> Assigned</span><span class=sym><span style='font-size:10.5pt;font-family:Courier;color:darkred'>(</span></span><span style='font-size:10.5pt;font-family:Courier'>P</span><span class=sym><span style='font-size:10.5pt;font-family:Courier;color:darkred'>)</span></span><span style='font-size:10.5pt;font-family:Courier'> <span class=kw><b>then</b></span><o:p></o:p></span></pre><pre><span style='font-size:10.5pt;font-family:Courier'> Writeln </span><span class=sym><span style='font-size:10.5pt;font-family:Courier;color:darkred'>(</span></span><span class=str><span style='font-size:10.5pt;font-family:Courier;color:blue'>'Pointer is initially NIL'</span></span><span class=sym><span style='font-size:10.5pt;font-family:Courier;color:darkred'>);</span></span><span style='font-size:10.5pt;font-family:Courier'><o:p></o:p></span></pre><pre><span style='font-size:10.5pt;font-family:Courier'> P</span><span class=sym><span style='font-size:10.5pt;font-family:Courier;color:darkred'>:=@</span></span><span style='font-size:10.5pt;font-family:Courier'>P</span><span class=sym><span style='font-size:10.5pt;font-family:Courier;color:darkred'>;</span></span><span style='font-size:10.5pt;font-family:Courier'><o:p></o:p></span></pre><pre><span style='font-size:10.5pt;font-family:Courier'> <span class=kw><b>If</b></span> <span class=kw><b>Not</b></span> Assigned</span><span class=sym><span style='font-size:10.5pt;font-family:Courier;color:darkred'>(</span></span><span style='font-size:10.5pt;font-family:Courier'>P</span><span class=sym><span style='font-size:10.5pt;font-family:Courier;color:darkred'>)</span></span><span style='font-size:10.5pt;font-family:Courier'> <span class=kw><b>then</b></span><o:p></o:p></span></pre><pre><span style='font-size:10.5pt;font-family:Courier'> Writeln</span><span class=sym><span style='font-size:10.5pt;font-family:Courier;color:darkred'>(</span></span><span class=str><span style='font-size:10.5pt;font-family:Courier;color:blue'>'Internal inconsistency'</span></span><span class=sym><span style='font-size:10.5pt;font-family:Courier;color:darkred'>)</span></span><span style='font-size:10.5pt;font-family:Courier'><o:p></o:p></span></pre><pre><span style='font-size:10.5pt;font-family:Courier'> <span class=kw><b>else</b></span><o:p></o:p></span></pre><pre><span style='font-size:10.5pt;font-family:Courier'> Writeln</span><span class=sym><span style='font-size:10.5pt;font-family:Courier;color:darkred'>(</span></span><span class=str><span style='font-size:10.5pt;font-family:Courier;color:blue'>'All is well in FPC'</span></span><span class=sym><span style='font-size:10.5pt;font-family:Courier;color:darkred'>)</span></span><span style='font-size:10.5pt;font-family:Courier'><o:p></o:p></span></pre><pre><span class=kw><b><span style='font-size:10.5pt;font-family:Courier'>end</span></b></span><span class=sym><span style='font-size:10.5pt;font-family:Courier;color:darkred'>.</span></span><span style='font-size:10.5pt;font-family:Courier'><o:p></o:p></span></pre></blockquote><p class=MsoNormal>Giuliano<br><br>P.S. In some rare case when dealing with complex objects you might need FreeThenNil() in place of FreeAndNil(). Give a look to <a href="https://lists.lazarus-ide.org/pipermail/lazarus/2011-April/062743.html">https://lists.lazarus-ide.org/pipermail/lazarus/2011-April/062743.html</a><br><br><o:p></o:p></p><pre>-- <o:p></o:p></pre><pre>Do not do to others as you would have them do to you.They might have different tastes.<o:p></o:p></pre></div></body></html>