[Lazarus] Testing Assigned object

Marco van de Voort marcov at stack.nl
Mon Apr 25 15:57:53 CEST 2011


On Mon, Apr 25, 2011 at 10:15:57AM +0200, Hans-Peter Diettrich wrote:
> > (without specifically assigning it to NIL in the declaration)
> > 
> > var
> >   slTest     :TStringList;
> > 
> > begin
> >   if Assigned(slTest) then FreeAndNil(slTest); // gives exception
> > end;
> 
> When slTest is a local variable, you should initialize it to Nil. 

Just to be clear

Initialize it in code not in the declaration, since in the declaration afaik
that makes it a static variable instead of a truely local one, even when declared
with local scope.





More information about the Lazarus mailing list