Re: Initialization section
- From: "alanglloyd@xxxxxxx" <alanglloyd@xxxxxxx>
- Date: 12 Feb 2007 03:02:48 -0800
On Feb 12, 10:01?am, "Sven Pran" <no.dir...@xxxxxxxxxxxx> wrote:
"Rob Kennedy" <m...@xxxxxxxxxxx> wrote in messageLook up Constructors in Delphi help ...
news:539qo6F1rjj5iU1@xxxxxxxxxxxxxxxxxxxxx
.................
Are you aware that all the fields of an object are initialized to zero
values anyway? The mere act of instantiating a class sets all the object's
fields to zero.
Is this a feature that is documented anywhere or
is it just a matter of experience?
I can't remember having seen it documented so I
have made myself the habit of not trusting any initial
field state, and when I feel a need to be absolutely
safe I initialize special fields during onCreate.
"Unlike an ordinary method, which must be invoked on an object
reference, a constructor can be invoked on either a class reference or
an object reference.
To create a new object, a constructor must be invoked on a class
reference. When a constructor is invoked on a class reference, the
following actions take place:
Storage for a new object is allocated from the heap.
The allocated storage is cleared. This causes the ordinal value of all
ordinal type fields to become zero, the value of all pointer and class-
type fields to become nil, and the value of all string fields to
become empty.
The user-specified actions of the constructor are executed.
A reference to the newly allocated and initialized object is returned
from the constructor. The type of the returned value is the same as
the class type specified in the constructor call.
When a constructor is invoked on an object reference, the constructor
acts like a normal procedure method. This means that a new object is
not allocated and cleared, and that the constructor call does not
return an object reference. Instead, the constructor operates on the
specified object reference, and only executes the user specified
actions given in the constructor's statement part. A constructor is
typically invoked on an object reference only in conjunction with the
inherited keyword to execute an inherited constructor."
Alan Lloyd
.
- Follow-Ups:
- Re: Initialization section
- From: Hans-Peter Diettrich
- Re: Initialization section
- From: Sven Pran
- Re: Initialization section
- References:
- Initialization section
- From: Paul E. Schoen
- Re: Initialization section
- From: Rob Kennedy
- Re: Initialization section
- From: Sven Pran
- Initialization section
- Prev by Date: Re: Initialization section
- Next by Date: Re: Initialization section
- Previous by thread: Re: Initialization section
- Next by thread: Re: Initialization section
- Index(es):
Relevant Pages
|