I did come up with a workaround for this which solves the immediate issue. It involves much more sophistication than I was originally hoping for with these classes, but it appears to do the trick. For the application I am working on, it would be counter-intuitive to have the dynamic properties appear to the user in an order that did not match the order they were inserted in. In general the property names are not inserted in alphabetical order. So here is an outline of the solution:
- add a private, hidden property "dynPropOrder" for the class.
- restrict access to addprop() by making it private for the class.
- add a public addDynamicProperty(propertyName) method for the class, which inserts adds the dynamic property using addprop(), but also appends the property name to the hidden dynPropOrder property in a cell string array.
- overload the display(), properties() and fieldnames() methods to return the properties in the expected order using the hidden dynPropOrder attribute.
- add a removeDynamicProperty(propertyName) which does reverse operations for the specified property.
Does this seem overly complicated to anyone else? Like I said it works, but I am disappointed there did not appear to be a more straightforward way. I welcome any suggestions...