Default Value w/ NEW Class vs Class Declaration

It looks to me as if a default value defined in a class type is set when a class object is declared
but is NOT set when a NEW instance is created. Is this correct behaviour?

Consider the following:

DClsType  CLASS,TYPE
Value       BYTE(1)
          END

MyClsType CLASS,TYPE
DRef        &DClsType
          END

MyCls  CLASS(MyClsType)
Init     PROCEDURE
       END

If a DefCls object is declared using:
DefCls CLASS(DClsType) --- DefCls.Value = 1

If an instance of DCls is created using:
MyCls.DRef &= NEW(DClsType) -- MyCls.DCls.Value = 0

(My apologies if the code is not well formatted.)

Default value for a class property is definitely not supported. Use the Construct method to default values for properties.

2 Likes

Hopefully Capesoft will take note. I just spent considerable time sorting this out with default values within OfficeInside. No idea now if other classes have similar.

That’s actually really interesting.
I didn’t realize that

MyClass CLASS(DClsType)
  END

Would actually have Value defaulted to 1.
Learn something everyday (hopefully).

BUT just don’t count on it with NEW.

I would not advise that kind of use. Constructor is the only reliable way to go, IMO.

3 Likes