Delete cloned Controls

Good morning (o;

For an application that creates an individual user interface based on what a serial device returns I use Control templates to add buttons, labels and textfields…

Dim newField as DesktopTextField = new templateField
newField.Tooltip = "Wert zwischen " + tokens(2) + " und " + tokens(3)
newField.visible = true
newField.Text = tokens(1)
TextFields.Add(newField)

All fine so far…

But how would I go along to remove those Controls when not needed anymore?

thanks in advance
richard

Ah looks like method Close seems to be the right thing…

Closes a control.

Closing a control permanently removes the control from memory, making it impossible to access. You can close both non-indexed controls and indexed controls. When you close an indexed control, the indexes for the remaining controls will shift downward so that the indexes start with zero and are consecutive.

1 Like

Instead of DIMming, use a property for reference.

For instance, add newField() as DesktopTextField to the window.

Your code would then become:

newField.add(new templateField)
newField.Tooltip = "Wert zwischen " + tokens(2) + " und " + tokens(3)
newField.visible = true
newField.Text = tokens(1)
TextFields.Add(newField)

You can then do

newField(0).close

Using an array, you can add many controls. But you got to figure which index to use. Instead of an array, you can use a series of properties. But it is less elegant.

He might already be doing that with this code…

TextFields.Add(newField)

Well I hope it is doing that…at least it works pefectly after connecting and querying the device…and removing with a For Each when closing the serial connection :wink:

BTW: Can SerialConnection also be cloned like that?

Oops, you are right.