New topic: 

Looping through Window.Control and ContainerControls

<http://forums.realsoftware.com/viewtopic.php?t=47030>

         Page 1 of 1
   [ 2 posts ]                 Previous topic | Next topic          Author  
Message        eliott          Post subject: Looping through Window.Control and 
ContainerControlsPosted: Fri Feb 22, 2013 2:23 am                         
Joined: Sun Oct 17, 2010 9:46 am
Posts: 78
Location: Berlin, Germany                The Window.Control(index As Integer) 
function can not return ContainerControls since they are not subclasses of 
Control. They return an EmbeddedWindowControl instance instead, which is a 
subclass of Canvas.

Now I often would have liked to cast an EmbeddedWindowControl to its 
ContainerControl, which obviously is not possible. Since this issue is brought 
up from time to time in this forum, I thought I share my solution.

The function iterates over all runtime objects and compares the Graphics object 
- if the iterator's current object is a ContainerControl - with the 
EmbeddedWindowControl's one.

Function TrueControl(Extends win As Window, index As Integer) As Object
  If index > win.ControlCount - 1 Then
  Return Nil
  Else
  Dim c As Control = win.Control(index)
  If c IsA EmbeddedWindowControl Then
  Dim iterator As Runtime.ObjectIterator = Runtime.IterateObjects()
  Do Until Not iterator.MoveNext()
    If iterator.Current IsA ContainerControl Then
    If ContainerControl(iterator.Current).Graphics = 
EmbeddedWindowControl(c).Graphics Then
    Return ContainerControl(iterator.Current)
    End
    End
  Loop
  Else
  Return c
  End
  End
End Function
Of course the name of the function is a bit misleading - it should actually be 
ControlOrContainerControl(index As Integer).   
                             Top                timhare          Post subject: 
Re: Looping through Window.Control and ContainerControlsPosted: Fri Feb 22, 
2013 4:55 am                         
Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12075
Location: Portland, OR  USA                Clever.  I might be able to use 
this.    
                             Top             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 2 posts ]      
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to