Go Back   Access World Forums > Microsoft Access Discussion > Modules & VBA

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 11-30-2011, 08:41 AM   #1
papadilbert
Newly Registered User
 
Join Date: Nov 2011
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
papadilbert is on a distinguished road
Need help implementing property of base class in derived class.

In my base class (clsBase) I have Public aProperty As String and the Let and Get skeleton property methods.

In the derived class (clsDerived) I coded Implements clsBase.
I coded the Let and Get property methods, prefixing them with clsBase_xxxx.
That works great.

I can't figure out how to write the code in the derived class to refer to the base class property aProperty.

When I compile I get the following error in the derived class:
"Object module needs to implement 'aProperty' for the interface 'clsBase'

Following the pattern for methods being prefixed with the name of the base class I tried coding:

Dim clsBase_aProperty as String

That didn't work.

I know how to implement a method. How do I implement a property?

papadilbert is offline   Reply With Quote
Old 11-30-2011, 09:13 AM   #2
vbaInet
AWF VIP
 
Join Date: Jan 2010
Location: U.K.
Posts: 26,374
Thanks: 0
Thanked 2,423 Times in 2,389 Posts
vbaInet is a name known to all vbaInet is a name known to all vbaInet is a name known to all vbaInet is a name known to all vbaInet is a name known to all vbaInet is a name known to all
Re: Need help implementing property of base class in derived class.

It looks like you've solved this here:

http://www.access-programmers.co.uk/...d.php?t=218855
vbaInet is offline   Reply With Quote
Old 11-30-2011, 09:35 AM   #3
papadilbert
Newly Registered User
 
Join Date: Nov 2011
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
papadilbert is on a distinguished road
Re: Need help implementing property of base class in derived class.

I solved my problem with the wrong the method being executed but I haven't figured out how to reference the property contained in the base class.

Following the naming rule for derived methods, I tried coding
Private clsBase_aProperty

but I still get the same compile error.

papadilbert is offline   Reply With Quote
Old 11-30-2011, 11:45 AM   #4
MarkK
Super Moderator
 
MarkK's Avatar
 
Join Date: Mar 2004
Location: Vancouver BC
Posts: 7,761
Thanks: 10
Thanked 1,290 Times in 1,227 Posts
MarkK is a name known to all MarkK is a name known to all MarkK is a name known to all MarkK is a name known to all MarkK is a name known to all MarkK is a name known to all
First of all, "base class" is perhaps a bit of misnomer. I'd expect to hear that used where there is an inheritance relationship, which is very different from implementing an interface, and VBA does not support inheritance.
You've created a class module that defines an interface that other modules need to implement, but that interface definition carries no implementation itself, so there should be nothing in the interface definition to refer to.
So, in your interface class, say it's named IPerson, maybe you would see a property Get and a property Let, like ....
Code:
property get FirstName  as string
end property
property let FirstName(svalue as string)
end property
These are stubs and provide no functionality.

Now, in every module that implements that class I would expect to see something like ...
Code:
implements IPerson

private m_fname as string

property Get IPerson_FirstName as string
  IPerson_FirstName = m_fname
end property
property Let IPerson_FirstName(svalue as string)
  m_fname = svalue
end property
... noting that all implementation exists in the class that implements the interface.
Hope this helps...
Mark
__________________
formerly known as lagbolt | Windows 10 | Access 2010 | Visual Studio 2013 | "Institutions have a vested interest in perpetuating the problems to which they are the solution." - Clay Shirky
MarkK is offline   Reply With Quote
Old 11-30-2011, 01:48 PM   #5
papadilbert
Newly Registered User
 
Join Date: Nov 2011
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
papadilbert is on a distinguished road
Re: Need help implementing property of base class in derived class.

OK... a class that defines an interface.

And when that interface has a public property, that property must be identified in the implementation class. I'm asking how to code that. Your example shows how to code the methods. That I figured out yesterday.

Are you suggesting that interfaces cannot contain properties? I haven't read anything that states that. But then, I haven't been able to find how to define it in the implementation either.
papadilbert is offline   Reply With Quote
Old 11-30-2011, 03:07 PM   #6
MarkK
Super Moderator
 
MarkK's Avatar
 
Join Date: Mar 2004
Location: Vancouver BC
Posts: 7,761
Thanks: 10
Thanked 1,290 Times in 1,227 Posts
MarkK is a name known to all MarkK is a name known to all MarkK is a name known to all MarkK is a name known to all MarkK is a name known to all MarkK is a name known to all
An interface is a class.
An interface may expose properties, functions, subs, and/or variables.
An example of what might appear in an interface is my first block of code above, which is indeed a property, but it could be a function or a sub or a public variable.

A class that implements an interface must expose members that exactly match all the public members of the interface. All parameters and return values and sub/function signatures must be exactly the same as those defined by the interface--and member names must be prefixed with the name of the interface. My second block of code demonstrates a class that implements the interface defined in my first block of code.

Quote:
And when that interface has a public property, that property must be identified in the implementation class. I'm asking how to code that.
The code I posted does exactly that. The first block is a public property in an interface. The second block is a class that implements it defines how it works.

Quote:
Your example shows how to code the methods. That I figured out yesterday.
My example shows how to code properties. A method is a behavior exposed by a function or a sub.

Quote:
Are you suggesting that interfaces cannot contain properties?
No. My first example shows an interface that contains a property. My second example shows a class implementing that interface defining the functioning of that property and exposing it.

Making sense?
These are complicated topics.
Cheers,
__________________
formerly known as lagbolt | Windows 10 | Access 2010 | Visual Studio 2013 | "Institutions have a vested interest in perpetuating the problems to which they are the solution." - Clay Shirky
MarkK is offline   Reply With Quote
Old 12-01-2011, 06:11 AM   #7
papadilbert
Newly Registered User
 
Join Date: Nov 2011
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
papadilbert is on a distinguished road
Re: Need help implementing property of base class in derived class.

A property denotes a storage location to store a value.

VBA OOP has decided to use the word "Property" as a qualifier but in reality they are Let and Get methods.

The first block does not contain a property. It contains 2 methods to Let and Get a property called "FirstName" that has not been defined. To define the property it would look like:

Public FirstName as String

When the property is coded, the compiler looks for an implementation of the public property. I am now more convinced that an interface cannot contain a property like the one above, but only methods.

I can deal with that. I just wanted to be sure that I wasn't missing something.

Thanks for taking the time to help me understand. It's a pleasure to find people like you who are willing to share their knowledge and talent!!


papadilbert is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Correct syntax to make Class Function Private yet callable by instances of Class mdlueck Modules & VBA 4 11-07-2011 07:32 AM
unable to set axis group property of the series class david99 Modules & VBA 1 11-19-2009 04:01 AM
Passing one Class Module variable into second class module mcdhappy80 Modules & VBA 1 09-12-2009 10:56 AM
vba class mikevds Forms 5 02-25-2009 10:53 AM
1004 Unable to set the Values property of the Series class keirnus Modules & VBA 18 09-26-2008 03:33 AM




All times are GMT -8. The time now is 07:36 AM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World