Constructor vs Window control initialization

So is THIS a bug?

Canvas subclass has integer property “property1” that is initialized thusly in the class’s Constructor:

// Calling the overridden superclass constructor.
Super.Constructor

property1=234

But when you inspect a canvas instance during runtime, property1 is 0.

If you put the code into the Open event of the abstract class, it works as expected. I imagine this is because the order of events is Constructor and then Window initialization, which makes sense but is nonsensical.

Before opening the door of a house, it must be constructed. Why is it non sensical ?

It has been burried in the forum so I could not find it back, but I remember reading a while ago that properties values set in constructor get lost when the control opens.

This sounds slightly paradoxical to me:[quote=175977:@Eric Williams]which makes sense but is nonsensical.[/quote]

AFAIK this is order:

For all controls Control Constructor Control IDE property settings are applied Control Open event Next Window Constructor Window IDE property settings are applied Window Open event
When the Open event is raised, the control or window is set-up properly – including the IDE property settings applied –, but not yet visible.

Eli’s bang on

The IDE effectively writes code that calls “Constructor” on your control class to get a new instance.
At that point all properties exist and are default values for their type.

Then all the properties are set - one at a time.

So If you write a control & try to rely on a property value in that controls constructor it can be “incorrect”.

We’d have to alter the control and magically add a constructor that took all the property values as arguments and set them and make the very last line a call your constructor with no arguments. And god forbid you had a constructor for a control that took some arguments but no zero argument form.

BUG is debatable.
Known behavior - most definitely.

A workaround is to make the property private or protected, along with regular method accessors.

[code]Class Class1 Inherits Canvas

Protected prop As Integer

Sub Constructor()
Super.Constructor
prop = 234
End Sub

Sub prop(assigns v As integer)
prop = v
End Sub

Function prop() As integer
return prop
End Function

End Class

MsgBox Str(Class11.prop) //234[/code]

Pretty squirrelly how scope changes this behavior but there you go.