Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#1135 Can't get setmethod working

None
invalid
Rick McGuire
None
none
1
2012-10-21
2012-10-21
Walter
No

4.0.1
a=.array~of('A','B')
if a~isa(.object) Then Say 'a is an .object'
if a~isa(.collection) Then Say 'a is a .collection'
if a~isa(.orderedcollection) Then Say 'a is an .orderedcollection'
if a~isa(.array) Then Say 'a is an .array'
if a~isa(.set) Then Say 'a is an .array'
Else Say 'a is not a .set'
a~setmethod('mod','Say mod')
/**********
2 - o~setmethod('mod','Say mod')
Error 97 running H:\book\smbug.rex line 2: Object method not found
Error 97.1: Object "an Object" does not understand message "SETMETHOD"
**********/

Discussion

  • Walter
    Walter
    2012-10-21

    correct test program:
    Parse Version v
    Say v
    a=.array~of('A','B')
    if a~isa(.object) Then Say 'a is an .object'
    if a~isa(.collection) Then Say 'a is a .collection'
    if a~isa(.orderedcollection) Then Say 'a is an .orderedcollection'
    if a~isa(.array) Then Say 'a is an .array'
    if a~isa(.set) Then Say 'a is an .array'
    Else Say 'a is not a .set'
    a~setmethod('mod','Say mod')
    /**********
    REXX-ooRexx_4.0.1(MT) 6.03 2 May 2010
    a is an .object
    a is a .collection
    a is an .orderedcollection
    a is an .array
    a is not a .set
    10 - a~setmethod('mod','Say mod')
    Error 97 running H:\book\smbug.rex line 10: Object method not found
    Error 97.1: Object "an Array" does not understand message "SETMETHOD"
    **********/

     
  • Rick McGuire
    Rick McGuire
    2012-10-21

    setMethod is a PRIVATE method, which means it can only be invoked from the context of a method of the same object. Invoked from any other context, the method not found message is the correct result.

     

  • Anonymous
    2012-10-21

    Thanks. I wonder if rexxref explains that somewhere (I haven't read it front-to-back)
    So, by adding this line to payroll's init:
    self~setmethod('mod','Say ''Method mod invoked''')
    I can use it from the main program (which is kind of a public use)
    me=.payroll~new('Walter',561985,333)
    me~raise(100)
    me~mod
    me~raise(100)
    ->
    salary increase from 333 by 100 to 433.
    Method mod invoked
    salary increase from 433 by 100 to 533.
    Method mod invoked

     
  • Rick McGuire
    Rick McGuire
    2012-10-21

    That is the meaning of PRIVATE. setMethod is the PRIVATE method with the restrictions. Methods added to the object are public scope, so they can of course be invoked in other contexts. Note #1 in the setMethod documentation clearly states it is PRIVATE and gives a link to the definition of private methods.

     


Anonymous


Cancel   Add attachments