[fpc-pascal] Checking if a TStringList already exists
James Richters
james at productionautomation.net
Tue May 21 15:48:11 CEST 2019
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
plotdraw.pax.pas(20,7) Error: Identifier not found "FreeThenNil"
James
From: fpc-pascal <fpc-pascal-bounces at lists.freepascal.org> On Behalf Of Giuliano Colla
Sent: Monday, May 20, 2019 6:01 PM
To: fpc-pascal at lists.freepascal.org
Subject: Re: [fpc-pascal] Checking if a TStringList already exists
Il 20/05/2019 15:23, James Richters ha scritto:
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.
James
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.
>From fpc documentation:
Program Example96;
{ Program to demonstrate the Assigned function. }
Var P : Pointer;
begin
If Not Assigned(P) then
Writeln ('Pointer is initially NIL');
P:=@P;
If Not Assigned(P) then
Writeln('Internal inconsistency')
else
Writeln('All is well in FPC')
end.
Giuliano
P.S. In some rare case when dealing with complex objects you might need FreeThenNil() in place of FreeAndNil(). Give a look to https://lists.lazarus-ide.org/pipermail/lazarus/2011-April/062743.html
--
Do not do to others as you would have them do to you.They might have different tastes.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20190521/8c373e71/attachment.html>
More information about the fpc-pascal
mailing list