When default values are not what they should be …

Just a heads up for anyone who’s default values are not what they should be:

Thanks to ARBED (http://www.tempel.org/Arbed) I just found the solution to a weird problem.

I have a custom canvas customCan. It had a property ZoomFactor as integer which was set to 3.

As the project developed I changed ZoomFactor to a computed property. I also set its default value to 5.

In a window I have a canvas, and its super is set to customCan. It could be (can’t remember but it seems likely) that originally it just had a super of Canvas and a property ZoomFactor with default 3, and that the property was moved to the custom class.

When I run the project and follow it in the debugger I see that ZoomFactor is 5 in the customCan constructor, then it goes to the Window constructor and ZoomFactor is suddenly 3.

I searched but absolutely nowhere in the project do I still have a 3, or set the ZoomFactor to 3.

Opening the project in ARBED I see that the instance (?) on the window has a property ZoomFactor = 3 which is NOT shown in the IDE.

I can’t delete it in ARBED, but I can set it to 5.

P.S. Will see if I can reliably do this in a small sample project and submit a bug report. Or does anyone know of one already?

Such a default value is read once from the subclass, and that is when the instance is created on the window. So you will need to delete the instance on the window and create a new one, then the change of the default value in your subclass will show.

More info:

Made a completely new canvas in the old non-corrected project, set its super to customCan, and following in the debugger.

It to shows a value of 5 for ZoomFactor in the customCan constructor which went to 3 in the window constructor.

I looked at the property list behaviour of customCan: there is a property ZoomFactor listed with a value of 3, not the value of 5 as specified in the IDE.

I open the version corrected by ARBED. It runs with a ZoomFactor of 5, and I expected to see this in the property list as well, but when I check the property list behaviour of customCan the ZoomFactor there is stated as being 3.

Somewhat topsy-turvy.

Thanks Eli, that’s what I suspected too but it doesn’t seem to be the case.

Btw I had also deleted the computed property ZoomFactor from the customCan and remade it but that too made no difference.

Ok, deleted the computed property again from customCan, added it as a normal integer, set the default to 5, changed it to a computed property again.

At every step I checked the property list and it always was 5.

It seems the project somehow kept a reference to the original non-computed property ZoomFactor which was not removed when the property was converted.

Deleting the computed property and adding a computed property did not help as it still showed a value of 3 in the property list.

Instead I needed to create a normal property ZoomFactor first, and then convert it to a computed property to get rid of the default of 3.