lost track with containercontrols

In my app I entered this code

dim w as window1 = new Window1

The module that creates this window also embeds in this window a ContainerControl (ccCounters), containing a PushButton and several TextFields

dim ccCtrs As new ccCounters ccCtrs.EmbedWithin(w,0,0,w.Width,15)
The same module wants to address a TextField in the ContainerControl
So I try
w.ccCtrs.Textfield(3).BackColor = &cFFDBB700
But this doesn’t work. (scope of the controls = public)

Probably I have a blackout… but
Why doesn’t it work and what is the right way to do this.

w.ccCtrs can’t work because you create the control at runtime. Make the container a property of the window and try again.

Store a reference of the container in a variable of type ccCounters in the window. Say, make it myCounters and then after you create the new instance of the container set myCounters = ccCtrs

Then, when you want to access the contents you could say:
w.myCounters.Textfield(3).BackColor = &cFFDBB700

I forgot to mention that I already did this

dim ccCtrs As new ccCounters ccCtrs.EmbedWithin(w,0,0,w.Width,15) w.ccCtr = ccCtrs
where ccCtr is a property(containercontrol) of window1

But even then I cannot do this
w.ccCtr.TextField(3).BackColor = &cFFDBB700

Hm…what is the error you are getting?

“ContainerControl” has no member named “TextField1”


If different than this:

TextField1 != TextField. I suggest that you double check the name and make sure that the control is not set to Private.

If I write

dim h as Integer = w.ccCtr.height

this works
So he sees the ContainerControl on the window1

That would indicate that it’s something to do with the Text control you’re trying to reference.

That’s obvious but
I also have a PushButton in the ContainerControl and he doesn’t see that either.

w.ccCtr.TextField(3) is not valid. “TextField” is not a possible instance name of a TextField. And TextField(3) would mean that you have a ControlSet of text fields. Is that the case?

it is

I overlooked this above

What is the Scope on the controls in ccCounters? This is in the ID Section of the Navigator.


[quote=238856:@roland brouwers]If I write

dim h as Integer = w.ccCtr.height

this works
So he sees the ContainerControl on the window1[/quote]

Step by step ; have you tried to check for a custom property of ccCtr ?

Have you tried to drag a simple control like a label that is not in a control set, and tried to access its property, something like

System.debuglog w.ccCtr.Label1.Text

If you look at the image I included you will see a Pushbutton which is not part of a controlset.
He doesn’t see that either

Wondering if ccCtr is what you think it is. This will list all controls on it.

for i as integer = 0 to w.ccCtr.ControlCount-1 system.DebugLog w.ccCtr.Control(i).Name next

Re-reading your initial post, I’d say you have an issue with the window. You write that you create the window like that:

dim w as window1 = new Window1

This means that you will not have access to the window outside of the method where this code is located. w should be a property of your module (or App), which you then set like that:

w = new Window1

Another thing: if you have code like:

w.ccCtr.TextField(3).BackColor = &cFFDBB700

… you always should test for Nil first:

If w Is Nil Then // error End If w.ccCtr Is Nil Then // error End w.ccCtr.TextField(3).BackColor = &cFFDBB700

If w is not Nil and ccCtr is not Nil your code will work.

I don’t know how system.DebugLog works or where I can see the output
So I put the code in my app and a stop at system.DebugLog and got this: