Accessing a control from control array 
Author Message
 Accessing a control from control array

I'm having trouble accessing individual controls from the control array.
Example:

dim i as integer
Dim r as rectControl

for i = 0 to controlCount - 1
  if control(i) isa rectControl then
    r = control(i) // Gives "type mismatch" error and will not proceed
    r.visible = false
  end if
next

Obviously, I want my code to do more than this, but this is a very stripped
down version of what I'm after. This keeps giving me "type mismatch" errors
and won't allow the program to run. Is this code wrong?

Please help!



Sat, 08 Nov 2003 09:32:05 GMT  
 Accessing a control from control array


Quote:
> dim i as integer
> Dim r as rectControl

> for i = 0 to controlCount - 1
>   if control(i) isa rectControl then
>     r = control(i) // Gives "type mismatch" error and will not proceed
>     r.visible = false
>   end if
> next

The problem is that "r" is a RectControl variable and "control(i)" is a
Control variable, even though the object referenced by control(i) "isA"
RectControl.  You'll have to explicitly cast control(i) to the
RectControl class, like so:

     r = RectControl(control(i))

...or, if you only need to access properties of the Control class (like
"visible"), just do "control(i).visible = false" instead of using r.

--



Sat, 08 Nov 2003 10:26:46 GMT  
 Accessing a control from control array
On 5/21/01 7:26 PM, in article

Quote:



>> dim i as integer
>> Dim r as rectControl

>> for i = 0 to controlCount - 1
>>   if control(i) isa rectControl then
>>     r = control(i) // Gives "type mismatch" error and will not proceed
>>     r.visible = false
>>   end if
>> next

> The problem is that "r" is a RectControl variable and "control(i)" is a
> Control variable, even though the object referenced by control(i) "isA"
> RectControl.  You'll have to explicitly cast control(i) to the
> RectControl class, like so:

>    r = RectControl(control(i))

> ...or, if you only need to access properties of the Control class (like
> "visible"), just do "control(i).visible = false" instead of using r.

> --


Thanks for your response. The first recommendation worked, however, the
second one did not. Controls do not seem to have a "visible" property.
Thanks for helpin' out. :)


Sat, 08 Nov 2003 18:17:18 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Delete a control from a control array

2. Control arrays in custom controls

3. Can a control reference its control array?

4. How to access array controls by keyboard?

5. control arrays and menu arrays

6. REAL Control Strip 1.0 - control strips for REALbasic applications

7. Creating a new control-class based on two or more standard controls

8. Disabling controls depending on other control values

9. Control-C and Control-Shift-C in VisualWorks 3.0

10. Entry control mysteriously CLEARED upon ACCEPT of control

11. Make the text control behave like the entry control

12. Loading Controls for control file.

 

 
Powered by phpBB® Forum Software