Dynamic Controls not displaying

I’m trying to create a series of text boxes in a window, using an existing text box as a template.
I have followed the code under Dynamic Controls in the User Interface Book.
The new controls seem to get created as I can access their values such as .top, .left, etc both in a message box and in the debugger,
But they won’t display on the form. I have Enabled, made Visible, put text in the Text attribute, refreshed and reShown the window, but they just don’t display.
I’ve shown the code below. Also, I seem to have to pre-size the variable that is used with the NEW directive. I.e. I have to give it dimensions. If I use () or (-1), I get runtime errors complaining about out-of-bounds indexes! There must be a way to declare it with no dimensions so it is truly dynamic?

Any help would be appreciated. I’m avery experienced programmer, but new to XOJO…Thanx…Markp

Code:

dim myFile as FolderItem
dim d as opendialog
d = new opendialog
dim t as TextInputStream
dim FirstLine as String
dim TwoCharNums() as String

dim Cell, LMargin, TMargin, R, C, CellHeight, CellWidth, RowTop, LeftMargin as Integer
Dim MazePath(64) as MazePathT

NumCols = 0
NumRows = 0

myFile = d.ShowModal ’ Get the file containing the input parameters for the maze

if myFile = nil then
MsgBox “You must select an input file containing the parameters that define the Maze.”
Return
Else
t = TextInputStream.Open(myFile)
FirstLine = t.ReadLine
TwoCharNums = FirstLine.Split(",") ’ Parse the first line into two strings

    if Ubound(TwoCharNums) = 1 then   ' Make sure we got two numbers
  
      NumCols = cdbl(TwoCharNums(0))
      NumRows = cdbl(TwoCharNums(1))
    Else
       msgbox "It appears the first line of the selected file does not contain a width and height specification in the form: 8,10.  The value found is: " + EndOfLine + FirstLine
       Return
    End If

End If

’ We now know how big the maze should be, so create the visual maze on the screen first, then read the rest of the input file to get the pattern for the maze

Cell = 0
LMargin = MazePathT(0).left ’ This is set as a Member of MazePathT, index 0 in the IDE
TMargin = MazePathT(0).top
CellHeight = MazePathT(0).Height
CellWidth = MazePathT(0).Width

For R = 1 to NumRows
RowTop = TMargin +((R-1) * CellHeight) + ((R-1) * 1)

For C = 1 to NumCols
  LeftMargin = Lmargin + ((C-1) * CellWidth) + ((C-1) * 1)
  Cell = Cell + 1
  MazePath(Cell) = New MazePathT(0)
  MazePath(Cell).Left = LeftMargin
  MazePath(Cell).Top = RowTop
  MazePath(Cell).Enabled = True
  MazePath(Cell).Visible = True
  MazePath(Cell).Text = str(Cell)
  MazePath(Cell).Border=True
Next
msgbox "Top = " + str(MazePath(Cell).Top)

Next

[quote=180063:@Mark Pankhurst]I<…>
For C = 1 to NumCols
LeftMargin = Lmargin + ((C-1) * CellWidth) + ((C-1) * 1)
Cell = Cell + 1

  MazePath(Cell) = New MazePathT(0)

  MazePath(Cell).Left = LeftMargin
  MazePath(Cell).Top = RowTop
  MazePath(Cell).Enabled = True
  MazePath(Cell).Visible = True
  MazePath(Cell).Text = str(Cell)
  MazePath(Cell).Border=True
Next

<…>
[/quote]

It seems to me that you are not instantiating from the correct control. The example in the docs does not show any reference to element 0 of a control array. Just this:

[quote]This example creates a new instance of a pushbutton called “Pushbutton1” then sets its caption. Add a PushButton to a window and name it PushButton1. Set its Index property to zero, making it the first element in a control array. Set its Caption property to “Original”.
In its Action event, create a clone of the pushbutton and enter this code
[/quote]

Dim pb As PushButton pb=New pushbutton1 pb.caption="Clone" pb.Left=Me.Left+Me.Width+10

[quote=180063:@Mark Pankhurst]The new controls seem to get created as I can access their values such as .top, .left, etc both in a message box and in the debugger,
But they won’t display on the form. I have Enabled, made Visible, put text in the Text attribute, refreshed and reShown the window, but they just don’t display.[/quote]

When you create a new TextField from one that is in a ControlSet, it appears exactly at the same place as the previous one. You must move it to see it.

So for instance if you have a TextField1(0) on your window, if you simply go dim ntf as new TextField1 it will seem not to show. You must do ntf.Left = TextField1(0).left+TextField1(0).Width to see it appear right next to it.

That may be the difficulty you have.

Whenever something does not work, don’t try to keep a whole set of code as you posted. Come back to a very simple snippet and make sure it works before incorporating into a larger routine.

When instantiating the object use just the Control Set name, i.e., drop the (0)

MazePath(Cell) = New MazePathT

Thank you all for the help. I was moving the object already, so that was not the issue. However, changing the instantiating to NOT reference the (0) element of the template object did the trick. Perhaps the compiler could give a warning in the future!??Thanx…Markp

PROBLEM SOLVED!!