Board index » delphi » Can I assume Boolean is FALSE in create?

Can I assume Boolean is FALSE in create?

Very simple question

Suppose one has a class

   TMyClass = Class(TObject)
      FileName  : String;
      Modified  : Boolean;
   End;

If I call TMyClass.Create, can I assume that
  FileName will be '' and Modified = False
or do I have to write a create method to force
these values?

-John_Mer...@Brown.EDU

 

Re:Can I assume Boolean is FALSE in create?


Quote
John_Mertus wrote:

> Very simple question

> Suppose one has a class

>    TMyClass = Class(TObject)
>       FileName  : String;
>       Modified  : Boolean;
>    End;

> If I call TMyClass.Create, can I assume that
>   FileName will be '' and Modified = False
> or do I have to write a create method to force
> these values?

The answer is that you may assume null-string and false.

Delphi initializes all newly-created class objects to binary zeroes
(using AllocMem) before running the constructors.  All variables will
therefore be zero, nil, or empty-string unless otherwise initialized.

Thank-YOU Borl... er, Inprise!  :-)

Re:Can I assume Boolean is FALSE in create?


In Delphi 3 it doesn't seem like the variables will be initialised....
If you use Delphi 3 you'd better initialise 'em first :^)

--

Janus N. T?ndering
Email: janusnt<alpha>usa<dot>net
Please correct my email address if you
want to mail me....thanks

Quote
Sundial Services wrote in message <355A42C0.4...@primenet.com>...
>John_Mertus wrote:

>> Very simple question

>> Suppose one has a class

>>    TMyClass = Class(TObject)
>>       FileName  : String;
>>       Modified  : Boolean;
>>    End;

>> If I call TMyClass.Create, can I assume that
>>   FileName will be '' and Modified = False
>> or do I have to write a create method to force
>> these values?

>The answer is that you may assume null-string and false.

>Delphi initializes all newly-created class objects to binary zeroes
>(using AllocMem) before running the constructors.  All variables will
>therefore be zero, nil, or empty-string unless otherwise initialized.

>Thank-YOU Borl... er, Inprise!  :-)

Re:Can I assume Boolean is FALSE in create?


Quote
Sundial Services wrote:
> John_Mertus wrote:

> > Very simple question

> > Suppose one has a class

> >    TMyClass = Class(TObject)
> >       FileName  : String;
> >       Modified  : Boolean;
> >    End;

> > If I call TMyClass.Create, can I assume that
> >   FileName will be '' and Modified = False
> > or do I have to write a create method to force
> > these values?

> The answer is that you may assume null-string and false.

> Delphi initializes all newly-created class objects to binary zeroes
> (using AllocMem) before running the constructors.  All variables will
> therefore be zero, nil, or empty-string unless otherwise initialized.

> Thank-YOU Borl... er, Inprise!  :-)

All quite true, but I prefer not to rely on this.  The reason being, that
you end up with only a partial list of variable initializations in the
constructor.  I like them all to be there, that way I know everyone is
getting the proper starting value.

Bob Lee

Re:Can I assume Boolean is FALSE in create?


In article <6jd03q...@cocoa.brown.edu>,
  John_Mer...@brown.edu (John_Mertus) wrote:

Quote

> Very simple question

> Suppose one has a class

>    TMyClass = Class(TObject)
>       FileName  : String;
>       Modified  : Boolean;
>    End;

> If I call TMyClass.Create, can I assume that
>   FileName will be '' and Modified = False
> or do I have to write a create method to force
> these values?

      The fact that constructors initialize fields to 0 is
documented, which is to say yes, unless they make 0 = True
suddenly. Regardless, it seems like a good idea to intitialize
it explicitly - more clear to others who may not know thatit's
automatically initialized to 0, safer in case 0 is actually
True, safer in case you can't believe what you read on Usenet...

David C. Ullrich

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading

Other Threads