Initialization of Properties and Variables

Most likely a ridiculous question, but is it safe to assume that upon creating a New instance of a Class, all string properties will be blank and all integer/double/currency properties will be zero? Or should these be explicitly defaulted to zero?

Same question for dimming variables.

Thank you

This is correct. All properties (and variables) get assigned with their default values when they are initialized.

[quote=224201:@Mark Scardingo]Most likely a ridiculous question, but is it safe to assume that upon creating a New instance of a Class, all string properties will be blank and all integer/double/currency properties will be zero? Or should these be explicitly defaulted to zero?

Same question for dimming variables.

Thank you[/quote]

They will be the default value for the type. For numeric values this is zero, for objects it is Nil, arrays are an empty non-nil array, etc.

Will they not take on the value of the “Default” field in the Property editor?
They don’t seem to in my case…

I have an Integer property “CurrentRow”, with the “Default” value in the IDE set to -1.
When the property is first used, it’s value is 0. Shouldn’t it be whatever value I have set in the Default Field?

Be careful with COMPUTED PROPERTIES… when the window initializes it calls the SET event of each one… so they WILL have a value, but also it will execute any other code which may reference objects that are not yet created during the initialize phase

Good tip, Dave. In my case, I’m just speaking of a “regular” property.

I’d like to hear the “official” word on whether setting a default value in the IDE is pointless or not?

Ok, from reading the LG, it looks like the default value of a property SHOULD be whatever it’s set to in the IDE. In my case it’s not, so I’ll have to do some digging to see if there’s something in my code that’s changing it…

I had a scan through Feedback to see if there’s any bugs reported, but I don’t see any.