Over the weekend Anthony of GraffitiSuite fame helped me with some code that I thought was a problem with his Suite, but turned out was an issue with my code (thanks again Anthony). He introduced me to a different way of embedding containers that would also be more secure which I’m converting my code over to. The issue I have now is trying to figure out how to reach into these new containers to run a method.
I have a menu that when an item is selected it embeds my container within a webpage. When it does this, it also adds a reference to this new container in a currentPage property. This all works amazingly well! What I can’t seem to do is reference a method in one of these newly embedded containers from elsewhere in my code. I’ve tried to do currentPage.myMethod, but that always comes back with a ‘Type webcontainer has no member named myMethod’.
Does anyone have a suggestion for how I can get this to work? I’ve not seen this situation (or at least not recognized this situation) when I’ve looked through the forum. Below is the code that handles/creates these embedded containers.
if not IsNull( currentPage ) then
currentPage.Close
currentPage = Nil
end if
currentPage = newContainer
currentPage.EmbedWithin( Main, self.Left + self.Width, self.Top, main.Width - (self.Width + self.Left), self.Height )
You’ll need to cast currentPage e.g. newContainer(currentPage).myMethod. Of course if you have multiple different containers you’ll either need to remember what type of container currentPage is or use the ISA operator to work out which container you need to cast to.
I’ve spent a few frustrating hours trying to figure this out with no success. I do not understand casting, even after reading a number of forum messages. I’ve tried things based on the examples I’ve read about in the forums, but with no luck. The closest I’ve come to something working the following based on the info found in https://forum.xojo.com/40262-web-container-replacing/0.
ccSchoolSetup is the webcontainer that I have “embedded”
ccStudentList1 is a web container that is in ccSchoolSetup using the drag-and-drop method
main.ccAppMenu1.LoadContainer is the webcontainer variable that I created in the code I submitted with my original question.
GetList is the method I need to run (updates data in the ccStudentList1 screen)
CurrentPage is the variable (not an array) I save the current webcontainer in (see code in my original note)
Can someone point me toward some information that might help me solve this. I’m at a loss as to how this works.
At the risk of adding too much information…the following is the full list of code that makes this work:
Sub Action() Handles Action //in the action event of a button
LoadContainer(new ccSchoolSetup)
End Sub
Public Sub LoadContainer(NewContainer as WebContainer)
if not IsNull( currentPage ) then
currentPage.Close
currentPage = Nil
end if
currentPage = newContainer
currentPage.EmbedWithin( Main, self.Left + self.Width, self.Top, main.Width - (self.Width + self.Left), self.Height )
End Sub
Public Property CurrentPage as WebContainer
@Maurizio Rossi , thank you for some of your thoughts. When I make the changes you suggest (basically invert what I’ve got), I get a ‘this item does not exist’ error. My inverted code is:
A new day, fresh mind and a determination to not let this defeat me and I figured it out. I went through a number of the existing forum posts again as well as an old bkeeney blog post and I figured it out. Once it worked…it was sort of an obvious answer that was eluding me. Thanks to all those that helped, whether you realize it or not.