Web and embedwithin Exception

Working on “refreshing” container controls on a web page from an array. I have stripped out everything but the absolute minimum in attempts to get this working. (Michel has been a big help assisting me to this point - thanks!)

I first clear the controls on the page by looping through the array (from ubound downto 0) instantiate a local MyContainer variable then use “.close” to remove each container from the page. I am then using the below to add containers back to the page from the MyContainers stored in the CCList() array.

CCList() is a Page Variable of type MyContainer which is manipulated by other methods (AddContainer and RemoveContainer)
CCPosition is a Page Variable defining each container’s top value when embedding on the page

		Dim c as new MyContainer
		Dim total as Integer = Ubound(CCList)
		CCPosition = 75
		
		// Loop through CCList array populating the controls on the page
		For i as integer = 0 to total
				
				// create instance of container
				c = new MyContainer
				
				// instantiate c with container from array
				c = CCList(i)
				
				// Display the container on the webpage, left = 10
*** 				c.EmbedWithin(self, 10, CCPosition, c.width, c.Height) 
				
				// Increments the position by the size of MyContainer + 1
				CCPosition = CCPosition + 76
		Next

I receive a NilObjectException above ( ***) when executing after removing the containers from the page. I do not receive the error when embedding the containers to the page from the array during the initial load.

What am I missing, doing wrong, etc.? Any assistance is greatly appreciated.

Bob

What’s your code for removing them?

Here is the “remove”.

Dim total as Integer = CCList.Ubound
	
for i as integer = total downto 0
     cc = new MyContainer
     cc = CCList(i)

// checkbox on the container that identifies container to be removed
  If cc.RemoveMe.value = True Then
    // remove from array
     CCList.remove i
     // close the container
     cc.close
     CCPosition = CCPosition - 76
  End If
next

cc = new MyContainer is creating a new instance of the container, and then you replace it on the next line. It’s needless MyContainer creation so I’d remove it. It might not make any difference but let’s eliminate the obvious issues first.

I tend to make my invisible, first, then close it, and then remove it from the array. Not sure that will make any difference or not but that’s how I do it.

In your creation you have the line Dim c as new MyContainer and then create a new instance of MyContainer down below. Again, you can just do dim c as MyContainer because using new creates an instance you’re not using which will slow things down depending on complexity.

I suspect that you have code elsewhere that is interfering but without seeing the whole project it’s hard to know.

Thanks Bob, back to dissecting. I will go back through making your adjustments and see what happens. I know it has to be something trivial (doing too many things at one).

No worries. If I had to add up the time I’ve spent on ‘trivial’ I’d probably be very depressed.

UGH!
Still haven’t found out why this doesn’t work. I have it down to two methods, add and remove.

Add()

		cc = new MyContainer
		cc.ControlLineName.text = "c" + str(Ubound(CCList)+1)
		cc.EmbedWithin(self, 10, CCPosition, cc.width, cc.Height)
		CCList.Append cc
		
		CCPosition = CCPosition + 76

Remove()

		For i as integer = Ubound(CCList) downto 0
		cc = CCList(i)

		// Remove container from page and array if RemoveMe is checked
		If cc.RemoveMe.value = True Then
			cc.Visible = false
			cc.Close
			CCList.remove i
		End If
		Next

		// Remove all containers
		For i as Integer = Ubound(CCList) downto 0
				cc = CCList(i)
				cc.Visible = false
				cc.close
		Next 
		
		// Populate containers to page from CCList()
		CCPosition = 75  // top value for first container
		For i as integer = 0 to Ubound(CClist)
				cc = CCList(i)
				cc.EmbedWithin(self, 10, CCPosition, cc.width, cc.height)
				CCPosition = CCPosition + 76  // increment for next container's top value
		Next 

Where, and what exception do you get ?

Hi Bob,
after

cc.close

you can’t do another

cc.EmbedWithin

You must:

cc = new MyContainer cc.EmbedWithin(self, 10, CCPosition, cc.width, cc.height)

[quote=322994:@Bob Sellers]UGH!
Still haven’t found out why this doesn’t work. I have it down to two methods, add and remove.

Add()

		cc = new MyContainer
		cc.ControlLineName.text = "c" + str(Ubound(CCList)+1)
		cc.EmbedWithin(self, 10, CCPosition, cc.width, cc.Height)
		CCList.Append cc
		
		CCPosition = CCPosition + 76

Remove()

[code]
For i as integer = Ubound(CCList) downto 0
cc = CCList(i)

	// Remove container from page and array if RemoveMe is checked
	If cc.RemoveMe.value = True Then
		cc.Visible = false
		cc.Close
		CCList.remove i
	End If
	Next

	// Remove all containers
	For i as Integer = Ubound(CCList) downto 0
			cc = CCList(i)
			cc.Visible = false
			cc.close
	Next 
	
	// Populate containers to page from CCList()
	CCPosition = 75  // top value for first container
	For i as integer = 0 to Ubound(CClist)
			cc = CCList(i)
			cc.EmbedWithin(self, 10, CCPosition, cc.width, cc.height)
			CCPosition = CCPosition + 76  // increment for next container's top value
	Next 

[/code][/quote]
I’m confused with your remove because you remove the one you want, and then remove the rest of them? I suspect that’s the cause your issues.

You have the reference to the container in CCList why not just iterate through the array and change their top position rather than re-embedding? Something like this in the remove to adjust their heights after you’ve removed the one you want.

for i as integer = 0 to CCList.ubound dim cc as myContainer = CCList(i) cc.top = CCPosition CCPosition = CCPosition + 76 // increment for next container's top value next

[quote=322999:@Maurizio Rossi]Hi Bob,
after

cc.close

you can’t do another

cc.EmbedWithin

You must:

cc = new MyContainer cc.EmbedWithin(self, 10, CCPosition, cc.width, cc.height)[/quote]
Yes, of course. I’ve been using WebContainers since it was an alpha version. If the OP is just rearranging the existing containers creating a new instance is the exact wrong thing to do.

Michel,
I receive the exception in “// Populate containers to page from CCList()” section of the Remove method, one line after “cc = CCList(i)”.

Mauirizo, I was doing that prior and still receiving the exception.

Bob, You are correct, I should be just repositioning rather than wiping the slate clean and reloading. Not sure how/why I went down the path of wiping and reloading from scratch. Let me try just adjusting the top property of each container.

Appreciate the assistance! This is really annoying.

30 seconds later and I am done! And I feel like a slug!
Thanks guys! One of these days I will be able to post answers to people’s questions and help someone else out like I have been.

@Bob Keeney - Give me a heads up if you are ever going to be in the Nashville, TN area, I owe you a beer!

Will do! I think the closest I’m getting to Nashville any time soon is Pigeon Forge (which isn’t that close).

Of course, you closed all containers in the previous loop:

[quote]// Remove all containers
For i as Integer = Ubound(CCList) downto 0
cc = CCList(i)
cc.Visible = false
cc.close
Next [/quote]