Reaching into a Dynamic Container

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.

Or define a Class Interface and cast currentPage as the interface.

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.ccStudentList1(main.ccAppMenu1.LoadContainer).GetList

When I run this, I get a 'Not enough arguments: missing WebContainer value for parameter “NewContainer”.

if I try the following, I get a ‘this item does not exist’ error.

ccSchoolSetup.ccStudentList1(main.ccAppMenu1.currentPage).GetList

  • 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

Thank you…

Casting is simple.

TypeName(PropertyName)

Means: the property named PropertyName must be assumed to be of type TypeName.

If I’ve understood correctly your code:

ccSchoolSetup.ccStudentList1(main.ccAppMenu1.LoadContainer).GetList

you are doing exactly the opposite i.e. you are using the property named ccStudentList1 as a type name.

@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:

main.ccAppMenu1.CurrentPage(ccSchoolSetup.ccStudentList1).GetList

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. :slight_smile:

ccSchoolSetup(main.ccAppMenu1.CurrentPage).ccStudentList1.GetList