Results 1 to 5 of 5

Thread: Help: Adding Property to Class that use IMPLEMENTS

Hybrid View

  1. #1
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    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

  2. #2

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    12

    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 -

    Quote 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.

  3. #3
    Fanatic Member Comintern's Avatar
    Join Date
    Nov 2004
    Location
    Lincoln, NE
    Posts
    826

    Re: Help: Adding Property to Class that use IMPLEMENTS

    Quote 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:
    1. Public Property Get IHuman_Salary() As Double
    2.  
    3.     Call Err.Raise(438, "CEmploye", "Object doesn't support this property or method.")
    4.  
    5. End Property
    6.  
    7. Public Property Let IHuman_Salary(ByVal uData As Double)
    8.  
    9.     Call Err.Raise(438, "CEmploye", "Object doesn't support this property or method.")
    10.  
    11. 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)

  4. #4
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    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:
    1. Private Sub Form_Load()
    2.     Dim oEmp as CEmploye
    3.     Dim oHuman as IHuman
    4.  
    5.     Set oEmp as New CEmploye
    6.     Set oHuman = oEmp
    7.  
    8.     oHuman .Name = "Mike"
    9.     oHuman .Sex=0
    10.  
    11.     oEmp.Salary = 1000  
    12.  
    13. 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
  •  



Click Here to Expand Forum to Full Width