I was needing to identify specific instances of a DesktopContainer inside a window. For DesktopContainer, the Name property is not accessible in code. I added a property “Name” to the Super and was going to assign values to its instances in the window when I noticed that the new property was already “self assigning” the Name as seen in the IDE.
A hidden property had been exposed, but is it safe to use? Are there reasons it was hidden?
Example use: make visible or invisible or enabled or, etc… different instances of a Desktop Container depending on the characters in its Name.
Demo adding Name property to DesktopContainer: ContainerName.zip (7.6 KB)
One possible explanation, given in the thread to which you linked, is that referring to objects by name is both unnecessary and ill-advised in a strongly typed object system like Xojo. You would be better served by storing references to your DesktopContainers and manipulating them that way.
Thanks, I take your point. The main objection I have to using the Name (or other property) is that the window method has to test each of the window’s objects to see if it is the Type of object being looked for and if its Name meets some criteria. Seems like a lot of runtime work compared to testing through predefined lists of objects. On the other hand, the number of objects on a form is relatively insignificant compared to Xojo’s speed.
Any thoughts on if exposing a Container’s Name in this way would cause problems that are outside of the Developer’s control, or does the Name exposed in this way work like any other property (apart from self populating).
If you keep a reference to each DesktopContainer you create, you won’t be doing any testing of names, types, etc. You’ll already have that information.
I wouldn’t use Name in this way. If you need some signifier of type or data storage, add a Tag As Variant property so you’re not risking a conflict with the framework.
Saw this in Docs, User interface, Desktop DesktopContainer: “!Note: At compile time, for historical reasons an underscore (_) is added to the name of any DesktopContainer instance. Be aware of this should you be using Introspection to check the name of a DesktopContainer instance.”
Anyway, I can see the wisdom in not relying on an undocumented feature that no one has confidence in.