Count objects

hi guys!

i need a little help…

Var c As Control
For i As Integer = 0 To Self.ControlCount - 1
  c = Window.Control(i)
  Select Case c
  Case IsA alemac_desktopTextField

and so on…

first… “control” is deprecated, but if i use “DesktopControl” it don’t work, because:
Expected class DesktopControl, but got class Control.

window, is also deprecated, … so i put desktopWindow, then:
Static reference to instance method: call this on an instance of class DesktopWindow

what’s the correct way to do this?

best regards,

alex

A better question might be to ask why you need to do this. Usually, when someone is iterating over a window’s controls, there’a an easier way to accomplish what they’re aiming for. :slight_smile:

1 Like

excellent! what’s the easy way?

Use a object.

Var o As Object

For i As Integer = 0 To Self.ControlCount - 1

  o = Window.Control(i)

  Select Case o

Or with “easier” syntax:

For Each o As Object In Self.Controls
  
Select Case o
...

Heh, you missed the point of my post. What are you trying to accomplish? Iterating through the controls is a process; I want to know the goal. That will help us best help you.

1 Like

hi @StefanA

thank you for the example.

i have about 30 objects on my window. some of them with a custom class. this is my actual code:

Dim nome As String
allRequired=True

For Each obj As Object In Self.Controls
  Select Case obj
  Case IsA alemac_desktopTextField
    nome = alemac_desktopTextField(obj).Name // just to debug
    If alemac_desktopTextField(obj).required=True Then
      If alemac_desktopTextField(obj).Text="" Then
        allRequired=False
        Return
      End If
    End If
  End Select
Next

why it does not enter the Case IsA alemac_desktopTextField ?

any guests?

Alex

Hi @Eric_Williams

I have a form with a lot of fields.

depending on who is going to access (ACL)
some fields are required (or not)

so i want to navigate thru the fields and check if they are required or not for that person.

this is an example. a simple example. it’s more complex than this.

Alex

Hard to say without any further code or information.
But it definitely works with custom classes:

untitled2.xojo_binary_project.zip (5.5 KB)

Is your control on a ContainerControl? If so it won’t show. Only controls directly on this window do. Containers don’t show ether, unless you use self.Objects, rather than Self.Controls.