|
-
Mar 31st, 2006, 12:50 PM
#1
Re: Help: Adding Property to Class that use IMPLEMENTS
You will need to add the Salary Property to the IHuman Interface, rather than to the CEmployee Class.
Declan
Don't forget to mark your Thread as resolved.
Take a moment to rate posts that you think are helpful 
-
Mar 31st, 2006, 01:15 PM
#2
Thread Starter
New Member
Re: Help: Adding Property to Class that use IMPLEMENTS
Thx...but i wanna get the reusable concept. From IHuman, maybe i'll write CStudent that has no Salary Property, but it has School Property beside Name,Sex and DateBirth...
- jude7 -
 Originally Posted by DKenny
You will need to add the Salary Property to the IHuman Interface, rather than to the CEmployee Class.
Last edited by jude7; Mar 31st, 2006 at 01:44 PM.
-
Mar 31st, 2006, 01:54 PM
#3
Re: Help: Adding Property to Class that use IMPLEMENTS
 Originally Posted by jude7
Thx...but i wanna get the reusable concept. From IHuman, maybe i'll write CStudent that has no Salary Property, but it has School Property beside Name,Sex and DateBirth...
- jude7 -
The interface -has- to be common to all the shared classes. As you have found out, VB6 doesn't support inheritance. One workaround would be to put all of the properties into the interface class as Declan suggests, but in that class's implementation of the property that is supposed to be 'missing', have it raise a "Method not found" error.
VB Code:
Public Property Get IHuman_Salary() As Double
Call Err.Raise(438, "CEmploye", "Object doesn't support this property or method.")
End Property
Public Property Let IHuman_Salary(ByVal uData As Double)
Call Err.Raise(438, "CEmploye", "Object doesn't support this property or method.")
End Property
It might sound kind of dumb to do it this way, but it will give the same result.
Last edited by Comintern; Mar 31st, 2006 at 01:56 PM.
Reason: typo (bad one)
-
Mar 31st, 2006, 02:46 PM
#4
Re: Help: Adding Property to Class that use IMPLEMENTS
You cannot reference the different interfaces through the same object variable. Since you declared oEmp as IHuman that interface is all you have access to. Your code should be
VB Code:
Private Sub Form_Load()
Dim oEmp as CEmploye
Dim oHuman as IHuman
Set oEmp as New CEmploye
Set oHuman = oEmp
oHuman .Name = "Mike"
oHuman .Sex=0
oEmp.Salary = 1000
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|