[Lazarus] Testing Assigned object

SteveG steveg at nevets.com.au
Mon Apr 25 09:28:20 CEST 2011


On 25/04/11 18:15, Hans-Peter Diettrich wrote:
> SteveG schrieb:
>> Is there a simple way to tell if slTest has been assigned in the
>> following ?
>>
>> (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.
> Otherwise the variable contains garbage, that most probably is *not*
> Nil, so that FreeAndNil tries to free something that never has been
> created.
>

Shall do - Thanks for that







More information about the Lazarus mailing list