I am trying to iterate through all the controls in a window, enabling/disabling ones whose parent is a specific control. The following is in a much simplified version of a method which takes the parentControl and value (True/False) as parameters:
Dim i As Integer
Dim ctl As Control
For i = 0 to winMain.ControlCount - 1
ctl = winMain.Control(i)
If ctl.Parent = parentControl Then <------ Gives error: "Type "Control" has no member named "Parent"
ctl.Enabled = value <------ Gives error: "Type "Control" has no member named "Enabled"
End If
Next i
I’m sure that I’m making a very stupid mistake here, but I’ve looked through the documentation and can’t find an example to explain what it might be.
RectControl has a Parent property, but not Control. You should check if the Control returned from the array is a RectControl and then cast and check its Parent property. I’m thinking something like this:
If ctl IsA RectControl Then
If RectControl(ctl).Parent IsA parentControl Then
RectControl(ctl).Enabled = value
End If
End If
Thanks Bob and Paul, that solved my basic problem and got me almost what I needed.
I’m actually doing something that is (strictly) not permitted - like embedding window controls on a container control [Paul, don’t yell at me ], so If rectcontrol(ctl).Parent Is parentControl Then doesn’t quite work, but I think that I have a workaround. At some point I may strike up a conversation on the correct way to build generalized controls which can be used as containers (similar to group boxes, but with more bells and whistles).
That’s exactly right Sam. But that brings up an interesting question (that I could certainly test in less than 30 seconds, but it’s more interesting to ask here…), does Xojo stop evaluation of a multi stage logic statement when it becomes False? I’ve always coded it as:
if rectControl( ctl ).parent <> nil Then
If rectControl( ctl ).Parent isa rectControl then
'Do something
end if
end if
This precludes a “Nil Object Exception” error when rectControl is Nil. If it does (stop evaluating the logic statement) then I’m impressed!