Suppose I have 2 WebContainers that can be used on WebPage1: DesktopWebContainer and MobileWebContainer. Depending on a check done in WebPage1.Shown, one or the other will be embedded within WebPage1. All controls in the 2 WebContainers are the same, with the same names. They’re just arranged differently on the screen for obvious reasons.
Now, I have WebPage1 Methods and Handlers that refer to controls in the embedded container. I want to use a Property for this: WebContainer1. That way I can have Methods and Handlers access the various controls in the embedded WebContainer like this: WebContainer1.TextField1.Text, WebContainer1.TextField2.Text, etc.
WebPage1.Shown will assign the appropriate WebContainer to Property WebContainer1.
My problem is that if Property WebContainer1 is of type WebContainer (the super of the 2 possible WebContainers that can be embedded), then the compiler won’t find WebContainer1.TextField1.Text or WebContainer1.TextField2.Text because they are not members of Class WebContainer. They are members of Subclasses DesktopWebContainer and MobileWebContainer.
Of course I can have 2 different WebPage1 Properties: DesktopWebContainer1 and MobileWebContainer1, and assign them the appropriate WebContainers in WebPage1.Shown. But then my Methods and Handlers will have to be completely re-written to access objects in the active WebContainer. That is, I would need a different dot prefix for one versus the other, to access, say, TextField1.Text: DesktopWebContainer1.TextField1.Text vs MobileWebContainer1.TextField1.Text.
Is there a way to programmatically change a Property’s Type? If so, I could solve this by keeping my single WebContainer1 property and change its Type to either DesktopWebContainer or MobileWebContainer, as needed.
Or perhaps there’s a more obvious way to solve this problem without having to rewrite my Methods and Handlers.