[fpc-pascal] Re: classes initialization

L L at z505.com
Wed Mar 26 00:32:03 CET 2008

Joao Morais replied to Jonas with:

 >I think I didn't get your point. What about this piece of code:
 >function foo: tfoo;
 > _foo: tfoo;
 >function foo: tfoo;
 > if not assigned(_foo) then
 >   _foo := tfoo.create;
 > result := _foo;
 >Is it safe?

What about this:

  _foo: tfoo = nil;

That way you declare it right there and then.. ensuring it is not assigned.

Hence why I think a good human practice is to always init everything 
even if it psychologically affects some people in ways such as "will 
this slow the program down though? Do I need to init this stuff if I am 
going to init some of it later"? which is evil premature optimization 
that causes bugs.


More information about the fpc-pascal mailing list