It is possible to pass a Control ?

It is possible to pass a Control to a Sub() ?

Certainly, you can either pass the exact class of control:

sub foobar( foo as Label)

or a more generic superclass:

sub foobar( foo as RectControl)

Which you want probably depends on what you intend to do with the Control…

Yes. For example:

Sub DoSomething(widget As TextField) widget.Text = "I did something" End Sub

be aware if you pass the superclass then you can only access those properties that are at that level, and not any in the class itself.

sub foobar(foo as label)

you can access .TEXT, plus all properties of the superclass rectcontrol

sub foobar(foo as rectcontrol)

you can ONLY access rectcontrol properties… even if Foo is a Label

You can test and coerce the type, taking different actions for different types. So…

sub foobar(foo as rectcontrol) if foo isa label then dim fl as label = label(foo) fl.Text = "something" elseif foo isa... ... end if end sub

Casting a control works for me…


SetPlatformFont (theControl as control)

  Select Case theControl
    
    //  only modify the system and smallsystem fonts to allow overrides in the IDE
    
  Case IsA BevelButton
    if BevelButton(theControl).TextFont = "System" then
      BevelButton(theControl).TextFont = app.kDefaultTextFont
    end if
    if BevelButton(theControl).TextFont = "SmallSystem" then
      BevelButton(theControl).TextSize = app.kDefaultSmallSystemFontSize
    end if
...