Announcement

Collapse
No announcement yet.

Inherited Objects?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Theo Gottwald
    replied
    But if it doesn't also inherit the instance variables, how are the methods and properties going to work?
    Hehe .. that really makes sense to me!

    Leave a comment:


  • Dominic Mitchell
    replied
    I forgot that it is implementation and not interface inheritance.

    Leave a comment:


  • A du Toit
    replied
    Well that is sad! So it is not working like JAVA!

    Leave a comment:


  • José Roca
    replied
    Well, the help file only talks about methods and properties:

    IMPLEMENTATION INHERITANCE is the process whereby a CLASS derives all of the functionality of an interface implemented elsewhere. That is, the derived class now has all the methods and properties of this new, extended version of a Base Class! This form of inheritance is offered by PowerBASIC, even though it is not required by the COM Specification.
    But if it doesn't also inherit the instance variables, how are the methods and properties going to work?

    Leave a comment:


  • Dominic Mitchell
    replied
    José, aren't class methods and instance variables private? I think there is a slight error in you code.
    Code:
    INSTANCE sStr AS STRING
    should not be included in the cB class.

    Leave a comment:


  • José Roca
    replied
    Whit INHERIT cA, iA, what you inherit are the methods of the interface iA of the class cA, not the interface iA, so cB becomes:

    Code:
    CLASS cB
     INSTANCE sStr AS STRING
     INSTANCE sStrB AS STRING
      INTERFACE iB
        INHERIT IUNKNOWN
        
        PROPERTY GET Desc() AS STRING
          PROPERTY = sStr
        END PROPERTY
    
        PROPERTY SET Desc(BYVAL sInStr AS STRING)
          sStr = sInStr
        END PROPERTY
    
        PROPERTY GET DescB() AS STRING
          PROPERTY = sStrB
        END PROPERTY
    
        PROPERTY SET DescB(BYVAL sInStr AS STRING)
          sStrB = sInStr
        END PROPERTY
      END INTERFACE
    END CLASS
    So ISINTERFACE is right saying that interface iA doesn't exist in the class cB.

    If it inherited the interface, it will become:

    Code:
    CLASS cB
     INSTANCE sStr AS STRING
     INSTANCE sStrB AS STRING
    
      INTERFACE iA
        INHERIT IUNKNOWN
        
        PROPERTY GET Desc() AS STRING
          PROPERTY = sStr
        END PROPERTY
    
        PROPERTY SET Desc(BYVAL sInStr AS STRING)
          sStr = sInStr
        END PROPERTY
      END INTERFACE
    
      INTERFACE iB
        INHERIT IUNKNOWN
        
        PROPERTY GET DescB() AS STRING
          PROPERTY = sStrB
        END PROPERTY
    
        PROPERTY SET DescB(BYVAL sInStr AS STRING)
          sStrB = sInStr
        END PROPERTY
      END INTERFACE
    END CLASS
    and you will have to use it as

    Code:
    FUNCTION PBMAIN () AS LONG
     LOCAL a AS iA
     LOCAL b AS iB
      B = CLASS "cB"
      
      a = b
      a.Desc = "TEST"
      b.DescB = "TESTB"
      
      MSGBOX a.Desc + " " + b.DescB
    
      MSGBOX STR$(ISINTERFACE(b, iA))
      
      MSGBOX STR$(OBJPTR(a))
    END FUNCTION
    As implemented by PB, is just a way top reuse the methods you have written for iA without having to cut and paste them in the interface iB of the class cB.
    Last edited by José Roca; 2 Sep 2008, 11:42 PM.

    Leave a comment:


  • jcfuller
    replied
    You might want to send that along to support.

    James

    Leave a comment:


  • A du Toit
    started a topic Inherited Objects?

    Inherited Objects?

    Hi All,

    I would like to understand the following situation, so please bear with me...

    Object B which is an intance of Class cB, Interface iB which is inhereted from Interface iA, Class cA. Now my question is Object b should have an interface which is supported by iA? Why is it not working as I expect?

    Here is a sample: (I expect STR$(ISINTERFACE(b, iA)) to return true... [])
    Code:
    #COMPILE EXE
    #DIM ALL
    
    CLASS cA
     INSTANCE sStr AS STRING
      INTERFACE iA
        INHERIT IUNKNOWN
        
        PROPERTY GET Desc() AS STRING
          PROPERTY = sStr
        END PROPERTY
    
        PROPERTY SET Desc(BYVAL sInStr AS STRING)
          sStr = sInStr
        END PROPERTY
      END INTERFACE
    END CLASS
    
    CLASS cB
     INSTANCE sStrB AS STRING
      INTERFACE iB
        INHERIT cA, iA
    
        PROPERTY GET DescB() AS STRING
          PROPERTY = sStrB
        END PROPERTY
    
        PROPERTY SET DescB(BYVAL sInStr AS STRING)
          sStrB = sInStr
        END PROPERTY
      END INTERFACE
    END CLASS
    
    FUNCTION PBMAIN () AS LONG
     LOCAL a AS iA
     LOCAL b AS iB
      B = CLASS "cB"
      
      b.Desc = "TEST"
      b.DescB = "TESTB"
      
      MSGBOX b.Desc + " " + b.DescB
    
      MSGBOX STR$(ISINTERFACE(b, iA))
      a = b
      
      MSGBOX STR$(OBJPTR(a))
    END FUNCTION
Working...
X
😀
🥰
🤢
😎
😡
👍
👎