Hello:
I am currently experimenting with Introspection and it’s quite nice. I could use a bit of guidance, however as I’ve run into a bit of an issue.
Here’s the scenario:
I created a subclass of a DesktopContainer and added a Property to it. I then created two more containers and set their Super to be that of my subclassed container. So far so good.
On a Window, I placed a DesktopSegmentedButton control with two buttons inside that control.
I figured out how to get the correct container (OneContainer and TwoContainer) to be visible depending on which segmentedbutton is clicked (it works fine). Here’s the code:
for each dc as DesktopContainer in Containers
if dc IsA OneContainer then
if OneContainer(dc).ContainerID = sbSelection.SelectedSegmentIndex then
if OneContainer(dc).isLoaded = false then
OneContainer(dc).EmbedWithin(self, sbSelection.Left, sbSelection.Top + 30, 300, 300)
OneContainer(dc).isLoaded = true
end if
OneContainer(dc).Visible = true
else
dc.Visible = false
end if
elseif dc IsA TwoContainer then
if TwoContainer(dc).ContainerID = sbSelection.SelectedSegmentIndex then
if TwoContainer(dc).isLoaded = false then
TwoContainer(dc).EmbedWithin(self, sbSelection.Left, sbSelection.Top + 110, 300, 300)
TwoContainer(dc).isLoaded = true
end if
TwoContainer(dc).Visible = true
var t as Introspection.TypeInfo = Introspection.GetType(dc)
for each prop as Introspection.PropertyInfo in t.GetProperties
if prop.Name.Lowercase = "containerid" then
var i as variant = prop.Value(dc)
end if
next
else
dc.Visible = false
end if
end if
next
Now, here’s what I’m “hoping” to do to make this even more flexible, however I’m likely overthinking things. Ultimately, I would like to be able to create even more of these subclassed containers (one for each new segmentedbutton I add) and not have to explicitly reference the concrete container object as I do in the above code example.
Here’s how far I’ve gotten thus far when execution reaches the line that reads: method.invoke(dc, p), I receive an illegalCastException and I cannot figure out which parameter is causing it or “if” I’m even on the right trajectory with this (see code below).
Once I can get this figured out, I’ll create a Xojo Library out of it and share it with any other projects that need to dynamically load, hide and/or display containers at run-time.
I’m close and on to something here. I can feel it!
var containerid as int32 = -1
var isLoaded as Boolean = false
for each dc as DesktopContainer in Containers
for each prop as Introspection.PropertyInfo in Introspection.GetType(dc).GetProperties
select case prop.Name.Lowercase
case "containerid"
containerid = prop.Value(dc).Int32Value
case "isloaded"
isLoaded = prop.Value(dc).BooleanValue
end select
if isLoaded = false then
if containerid = sbSelection.SelectedSegmentIndex then
var methods() as Introspection.MethodInfo = Introspection.GetType(dc).GetMethods
for each method as Introspection.MethodInfo in methods
if method.Name.Lowercase = "embedwithin" then
var p() as Variant
p.Add(dc)
p.Add(20)
p.Add(20)
p.Add(300)
p.Add(300)
method.invoke(dc, p)
end if
//CustomDesktopContainer(dc).isLoaded = true
//CustomDesktopContainer(dc).Visible = true
next
end if
end if
next
next
