Create controls programmatically

Hi all,
here a simple but may be problematic question:

Is it possible to take an empty window and to place controls on it programmatically?

I would need it to create text fields, check boxes, pop-ups etc. dependent on it’s type and length, coming from a database. So I do not know about the control until I create it. As far as I understood, containers would be a way to handle this - so I could take one container for each “type” and put this on the window … but I would have multiple containers of the same type then (?). How could that be addressed then?

Any idea would be very appreciated.

You have ‘off screen’ or visible = false controls of each type on the window, set to be part of a collection of controls each
You do this by assigning the control an ‘index’ of 0 in the inspector window

At run time, if you need 10 TextFields, you clone the original one 10 times
Each new one has a new index.
You refer to these as you would an array

Dim myTextField() As TextField for x as integer = 1 to 10 myTextField(x)= new myTextBox myTextField(x).text = format(x) myTextField(x).left = 20 myTextField(x).top = 20 + 20 * x myTextField(x).visible = true next

You also have to modify the Controls Tab Order (for the Control(s) you clone), else, one will get the focus and you will dislike; choose the TextField (the original, you have only this at design time) and set its Tab order as the last one of the list.

Also, in Jeff Case, you know how many Clones you have, but if you want to clear the clones contents in a true dynamic Control Set (one you do not know how many Controls in the set), you are in trouble.

I use:

[code]Dim Loop_Idx As Integer

// For Loop_Idx = 0 To Total_TF
While TF(Loop_Idx) <> Nil
// Clears the TextField contents
TF(Loop_Idx).Text = “”

// Inc the array indice
Loop_Idx = Loop_Idx + 1

// To avoid any infinite loop
If UserCancelled Then Exit

Wend[/code]
to clear the Control set contents.

This page is your friend:
http://documentation.xojo.com/topics/user_interface/desktop/desktop_controls/control_sets.html

@Michael Dettmer — You cannot create controls programmatically from scratch, just because there is no way you could insert executable code in the events, methods etc…

HOWEVER, you can have a Window containing some template controls (and the code they need) and duplicate them, position them in the window, change their properties etc. Usually, such controls must be declared as part of a control set, unless you are sure that there will be only one instance of a control.

Thanks a lot for your help. Thank you also for the link - I did not see that. Very helpful.

This documentation is not my ork and I do not know if I could have done it i a better way, but it is sometimes very hard to reach what I am searching. In that case, I recalled the two important words to search for: Control Set. That helped to find the correct page.