But if it doesn't also inherit the instance variables, how are the methods and properties going to work?
Announcement
Collapse
No announcement yet.
Inherited Objects?
Collapse
X
-
I forgot that it is implementation and not interface inheritance.
Leave a comment:
-
-
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.
Leave a comment:
-
-
José, aren't class methods and instance variables private? I think there is a slight error in you code.
Code:INSTANCE sStr AS STRING
Leave a comment:
-
-
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
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
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
Last edited by José Roca; 2 Sep 2008, 11:42 PM.
Leave a comment:
-
-
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
Tags: None
-
Leave a comment: