I feel I’m being a bit slow of thinking today. What would be an elegant way to do this:
I have a window called win_Digest which has a protected property DigestSettings of class cDigestSettings. I made it protected as otherwise it might be a bit confusing if there is more than one win_Digest, each with their specific settings.
When a new win_Digest is being created then I showed a canvas with lots of controls where the user chose the relevant settings, and they were saved to the property DigestSettings.
To declutter the project I want to use ContainerControls instead of a Canvas but am having a bit of a problem.
I gave the ContainerControl ccSetDigestParameters a protected property DigestSettings of class cDigestSettings.
I wanted to set the DigestSettings property of the ContainerControl to be the one of the window.
But because of the protected scope I can’t set it with ccSetDigestParameters.DigestSettings = self.DigestSettings
What would be the recommended way to deal with this?
Should I stick with the canvas?
Should I change the scope of the DigestSettings?
Should I maybe define an event SetupFinished with code in the ContainerControl on the win_Digest?
I don’t understand exactly why your DigestSettings property has to be protected. Your window has only one property of this kind if I understand correctly. You will always address it via the window namespace from outside, so where is the risk of confusion? If you don’t want it to be overwritten incidentally, you could convert it to a computed property without a setter so the container control could read its parent’s DigestSettings in its open event. Of course you would have to cast your winDigest class to the parent first.
Or you could give your ccSetDigestParameters class a constructor in which you pass the window’s DigestSettings to the container’s property. If you define another constructor without a parameter and set its scope to private, you will not incidentally create a container control without passing the property.
Define a new event on the Containers base class
GetOwnersDigest() as cDigestSettings
In the Open event of the container raise this event and store the result in the protected
I might not store it and just ask for it every time since its simple enough to raise the event right when you need it
Then when you put an instance on the window you can raise the event & get it from the containing window with a nice clean API
And the containing window can change the instance at any time & the container is none the wiser