On Fri, 13 Oct 2006 19:58:22 +1300, Nicholas Sherlock
<N.sherlock@[EMAIL PROTECTED]
> wrote:
>J French wrote:
>> Further to Rob's points, you really need to set up a Flag of some sort
>> to indicate whether an object has been created
>>
>> You can rely on the instance pointer being Nil, provided you make darn
>> sure that it starts life off as Nil and you FreeAndNil it rigorously
>> - but the hassle, and the problems when one makes a mistake, far
>> outweigh the benefit of saving one explicit variable
>I don't get it. What work do you avoid, by using an explicit variable
>instead of simply nilling pointers that don't go anywhere useful?
Well, I used to use the: If Assigned( SomeObj ) Then approach
- but I found that I was having to make darn sure that I was doing
SomeObj := Nil at the begining of the routine because local
variables are not cleared when put on the Stack (except when they are
<g> )
I found that the code was getting less and less readable as I was
using the 4 byte object reference as a sort of substitute flag.
In my case it was generally a matter of creating a series of objects
and backing out if I ran into problems. Since backing out does not
happen that often, I found that I was building obscurity into little
tested code.
I think that nowadays I would use a nested Try Finally construct, with
Exit used to guarantee destruction of things that needed to be
destroyed.
While writing code, it is blatantly clear what everything really
means, it is just a problem six months later, getting ones head around
the subtle implications - hence my recommendatito write blatantly
obvious code.


|