Forum Discussion

georgejecook's avatar
georgejecook
Streaming Star
8 years ago

Any way to pass return value from extended component function?

I have Component BaseClass extends Group
it has a function SayHello as string

I then extend it with ExtendedClass extends BaseClass
it extends funciton SayHello as string

Is there any way for ExtendedClass to get the SayHello value returned from BaseClass?

3 Replies

  • Perhaps you can add two fields to the BaseClass, a boolean that signals BaseClass to run its SayHello function and the other field that receives the value returned by that function.  Then the ExtendedClass could make use of those fields to call and receive the BaseClass SayHello value.
  • in BaseClass.xml
    <field id="runSayHello" type="boolean" alwaysNotify="true" onChange="onRunSayHello" />
    <field id="sayHelloResponse" type="string" />


    in BaseClass.brs
    sub onRunSayHello()
      m.top.sayHelloResponse = SayHello()
    end sub


    in ExtendedClass.brs
    sub getBaseSayHello()
      m.top.observeField("sayHelloResponse","gotResponse")
      m.top.runSayHello = true
    end sub

    sub gotResponse()
      print "Response: "; m.top.sayHelloResponse
    end sub
  • Thanks,

    I use this strategy pattern extensively, in all languages. I was hoping that there'd be a provision for simple overriding; but more widely using deference, as you suggest, is just as good a solution.

    Appreciate the code snippets! Thanks!