Announcement

Collapse
No announcement yet.

Inherited Objects?

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

  • 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
    JADT

  • #2
    You might want to send that along to support.

    James

    Comment


    • #3
      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; 3 Sep 2008, 12:42 AM.
      Forum: http://www.jose.it-berater.org/smfforum/index.php

      Comment


      • #4
        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.
        Dominic Mitchell
        Phoenix Visual Designer
        http://www.phnxthunder.com

        Comment


        • #5
          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?
          Forum: http://www.jose.it-berater.org/smfforum/index.php

          Comment


          • #6
            Well that is sad! So it is not working like JAVA!
            JADT

            Comment


            • #7
              I forgot that it is implementation and not interface inheritance.
              Dominic Mitchell
              Phoenix Visual Designer
              http://www.phnxthunder.com

              Comment


              • #8
                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!
                --Theo Gottwald
                ------------------------------------------------
                76706 Dettenheim * Germany * [email protected]
                ------------------------------------------------
                Joses Forum * Theo's Link Site * IT-Berater.org

                Comment

                Working...
                X