Re: Assigned and FreeAndNil



procedure doSomething(const aCar:TCar);
begin
Assert(aCar<>nil);
showMessage('the car is:'+aCar.color);
FreeAndNil(aCar);
end;

Don't you mean "run time" checking when assertions are turned on? I don't
think you can test pointers for nil during compilation!

nope. you'll get this compile error on the FreeAndNil call:

[Pascal Error] E2197 Constant object cannot be passed as var parameter

and yes, of course the assert() is runtime, that was just an example of writing robust code..

> Your use of FreeAndNil is part of your philosophy of programming,
> rather than an imperative of the language.
yup. if you haven't read "code complete" recently, it's well worth it..

> I write a lot of code, and I don't get
> bad pointer trouble hidden in released executables.
thats fine. but as soon as something goes wrong, for whatever reason (think of all the third party code you run) then i would much rather debug code that uses assertions, appropriate const and var declarations, and freeAndNil. it just _eliminates_ entire categories of potential problems.

it adds up to _knowing_ that your program works correctly, rather than observing that it seems to.
.