Re: Assigned and FreeAndNil
- From: Ben Taylor <to_ben@xxxxxxxxx>
- Date: Fri, 27 Oct 2006 13:01:36 +1300
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.
.
- Follow-Ups:
- Re: Assigned and FreeAndNil
- From: Roger Lascelles
- Re: Assigned and FreeAndNil
- References:
- Assigned and FreeAndNil
- From: John Jacobson
- Re: Assigned and FreeAndNil
- From: Bob Dawson
- Re: Assigned and FreeAndNil
- From: John Jacobson
- Re: Assigned and FreeAndNil
- From: Bob Dawson
- Re: Assigned and FreeAndNil
- From: Wayne Niddery [TeamB]
- Re: Assigned and FreeAndNil
- From: Ben Taylor
- Re: Assigned and FreeAndNil
- From: Roger Lascelles
- Assigned and FreeAndNil
- Prev by Date: Re: Delphi
- Next by Date: Re: Turbo Delphi vs BDS 2006
- Previous by thread: Re: Assigned and FreeAndNil
- Next by thread: Re: Assigned and FreeAndNil
- Index(es):