Re: Initialization section



On Feb 12, 10:01?am, "Sven Pran" <no.dir...@xxxxxxxxxxxx> wrote:
"Rob Kennedy" <m...@xxxxxxxxxxx> wrote in message

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.

Look up Constructors in Delphi help ...

"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

.



Relevant Pages

  • Re: Initialization section
    ... fields to zero. ... a constructor must be invoked on a class ... ordinal type fields to become zero, the value of all pointer and class- ... When a constructor is invoked on an object reference, ...
    (comp.lang.pascal.delphi.misc)
  • Re: Please explain difference in ways to construct a javascript editor
    ... understand it) and the second method, which uses prototype functions. ... The language as used client-side in Web user agents so far has no ... CodePress.rundoes not make sense as it is a method of a constructor ... would overwrite the previously assigned object reference which would ...
    (comp.lang.javascript)
  • Re: overloading the ctor question
    ... > compile time, I get "An object reference is required for the nonstatic ... Second, The 'base' construct is only used on constructor functions, ... create a 'TestExample' and return it (set the return type ...
    (microsoft.public.dotnet.languages.csharp)
  • RE: {simple} Exception handling & Object references
    ... Put the call to new in you class's constructor... ... "War Eagle" wrote: ... > so that this line of code (which is in a private function that gets called when a button is clicked): ... > Object reference not set to an instance of an object. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: X509Certificate failure on new NIST X.509 test suite
    ... > The good news is that they all worked when using the ... > X509Certificateconstructor. ... Object reference not set to an instance of an ... > result with framework 1.1. ...
    (microsoft.public.dotnet.security)