Playing with Control Sets

I am a novice XOJO programmer with C, Java, C++ … experience but basic knowledge of XOJO programming…

Let’s explain my new problem:
I have a Window (MyWindow) with a ListBox (ListBox1) and one TextField (TextField1). Textfield1.Visible = False.
I want to create additional TextFields at runtime based on the number of columns in ListBox1. This is done in a loop (i is the loop index) in the Open() event of MyWindow:

Dim Tx As TextField Tx = new TextField1 Tx.Top=Textfield1(i-1).top+30

The TextFields are all displayed well. Now, I want to update the Textfields (TextField1(0), TextField1(1)… ) with the data in a row of ListBox1. I have the following piece of code in the change() event of ListBox1 (ArraySize is the number of columns in the ListBox)

Row = ListBox1.ListIndex If Row <> -1 Then For i As Integer = 0 To ArraySize-1 TextField1(i).Text=ListBox1.Cell(Row,i) Next End If

At runtime, the code breaks at the line TextField1(i).Text=ListBox1.Cell(Row,i). Debugging shows me that TextField1(1) is unknown. TextField1(0) is filled with data.

What is going wrong? Why is the array not available?

What is the exception you get on this line? I don’t see anything that looks obviously wrong but you’ve left out some parts of the code.

You might want to do this in steps. You have verified you can add the TextFields so the next thing would be to verify you can add text to all of them. Once you know that works you can add the ListBox handling you want.

Or you can post a link to your sample project so we can take a peek at it.

@Paul Lefebvre I get a NilObjectException with ArraySize=3, Row=0, i = 1. There are 4 columns in the ListBox and 4 rows.

Like I said, nothing jumps out at me. I did a quick test of basically the same code (without the ListBox stuff) and it worked fine here.

If you can share a link to a project with code that does this I can take a peek.

@Paul Lefebvre I also did a quick test with a Listbox (2 rows, 4 columns) and the same piece of code. I agree, this works fine!

So, I have to look to the context. Is it possible that instantiating MyWindow1 could be the problem?

Dim TestWindow As new MyWindow1

I don’t know what could be the problem since I haven’t seen your entire project. It would appear the problem is caused by some other code in your project (not what you’ve posted here). You certainly would get a NilObjectException if you tried to access TextFields that do not exist on the Window.

@Paul Lefebvre I found the problem: I instantiated MyWindow1 before I added additional TextFields to the Control Set of TextField1. Problem Solved!