[Lazarus] Difference between FreeThenNil and FreeAndNil

michael.vancanneyt at wisa.be michael.vancanneyt at wisa.be
Wed Apr 27 10:09:50 CEST 2011

On Wed, 27 Apr 2011, Alexander Klenin wrote:

> On Wed, Apr 27, 2011 at 18:46,  <michael.vancanneyt at wisa.be> wrote:
>> I mean, if one does
>>  FreeAndNil(MyObject);
>> It really doesn't matter whether the reference MyObject is set to nil before
>> or after the call to Free ?
> Sadly, it does, although I do not think it is a good programming practice.
> See my first mail in this thread ;-)

My collega explained to me what you meant (your original statement was not clear to me).

You're referring to cases like:

   MyForm : TMyForm

destructor TMyForm.Destroy;


and then somewhere


Which is simply wrong coding in the destructor.

I don't think you should provide for this. This is encouraging people to
write bad code. They should get an error, and correct their code.


More information about the Lazarus mailing list