WARN56-Parameter to FreeAndNil is not an object

Top  Previous  Next

 

Parameter to FreeAndNil is not an object (WARN56)

 

This section reports locations in your code where FreeAndNil takes a parameter which is not an object, for example an interface variable. This may lead to access violations. Unlike Free, the compiler will not complain.

 

Example:

 

clipx174

 

Note, that starting with Delphi 10.4 it is much harder to produce this warning, because FreeAndNil only accepts parameter based on TObject.

It is still however possible to produce the error, for example with code like:

 

FreeAndNil(TObject(IAnyInterface))

 

 

See also:

 

Alerts