Question about default properties 
Author Message
 Question about default properties

Consider the following class definition:

----pExample.cls----
Private m_Recordset As ADODB.Recordset

Property Let Recordset(RHS As ADODB.Recordset)
Set m_Recordset = RHS
End Property

Property Get Recordset() As ADODB.Recordset
Set Recordset = m_Recordset
End Property
----

The Recordset property is as the default so you can do code like this to
initialise the default property:

Dim rst as new ADODB.Recordset
Dim Example as New pExample
Example = rst

However, we'd like to be able to make the default read property a recordset.
You can do this:

Debug.Print Example.Recordset.State

but you can't do:

Debug.Print Example.State

which is a bit of a shame but I can understand why. This works though:

Debug.Print Example().State

but the problem with this is that the property wizard doesn't kick in, i.e.
when you get to Example(). it shows just the Recordset property not the
properties of ADODB.Recordset. Is there any way around this??

Strangely, if you replace the property get/let with a function like this:

Function Recordset(Fudge as Long) As ADODB.Recordset

Then typing Example(0).State and the property wizard displays the recordset
properties as expected when you get to the dot after the (0) bit.

Sadly, making the function definition:

Function Recordset() As ADODB.Recordset

Doesn't work in the same way, i.e. the wizard doesn't kick in.

All very inconsistent!

Cheers, Rob.



Mon, 24 Nov 2003 00:52:13 GMT  
 Question about default properties
Not exactly sure about the question... but I did notice that your example
code...
Quote:
> Property Let Recordset(RHS As ADODB.Recordset)

needs to be changed to

Quote:
> Property Set Recordset(RHS As ADODB.Recordset)

maybe it was just a sample eh? But.. you can set a class's default property
using the 'Tools/Procedure Attributes' menu/dialog.

And note that using *any* object's "default" property is going to require
you to change your code for VB.Net (if you plan on using it) because there
will be *no* default properties of any kind..


Quote:
> Consider the following class definition:

> ----pExample.cls----
> Private m_Recordset As ADODB.Recordset

> Property Let Recordset(RHS As ADODB.Recordset)
> Set m_Recordset = RHS
> End Property

> Property Get Recordset() As ADODB.Recordset
> Set Recordset = m_Recordset
> End Property
> ----

> The Recordset property is as the default so you can do code like this to
> initialise the default property:

> Dim rst as new ADODB.Recordset
> Dim Example as New pExample
> Example = rst

> However, we'd like to be able to make the default read property a
recordset.
> You can do this:

> Debug.Print Example.Recordset.State

> but you can't do:

> Debug.Print Example.State

> which is a bit of a shame but I can understand why. This works though:

> Debug.Print Example().State

> but the problem with this is that the property wizard doesn't kick in,
i.e.
> when you get to Example(). it shows just the Recordset property not the
> properties of ADODB.Recordset. Is there any way around this??

> Strangely, if you replace the property get/let with a function like this:

> Function Recordset(Fudge as Long) As ADODB.Recordset

> Then typing Example(0).State and the property wizard displays the
recordset
> properties as expected when you get to the dot after the (0) bit.

> Sadly, making the function definition:

> Function Recordset() As ADODB.Recordset

> Doesn't work in the same way, i.e. the wizard doesn't kick in.

> All very inconsistent!

> Cheers, Rob.



Mon, 24 Nov 2003 07:53:36 GMT  
 Question about default properties
Ken

Quote:
> will be *no* default properties of any kind..

I could be wrong here, I just haven't had time to play with .NET since the
pre-beta version, but I believe that you will still have default properties
on index type properties, so you can still do stuff like:

Obj(1) = "Something"

Anyway,  I think that for the most part you are correct, but I do believe
there is this one exception to the *no*.

Tom Shelton

PS:  Boy, I really got to start playing with .NET more.  I don't think I'll
have to hard a time making the transition, since I do have some C++/Java in
my background, but I think the hard part is going to be learning all the
libraries as well as the new syntax.



Mon, 24 Nov 2003 12:49:21 GMT  
 Question about default properties

Quote:
> Not exactly sure about the question... but I did notice that your example
> code...

In a nut shell, the question is can you create a class that when you do
something like:

set x = TheClass.TheProperty

TheProperty is actually the property of AnotherClass in this definition:

Property Get Default() as AnotherClass

The short answer, this don't work and shouldn't if you think about it...
Anything after the dot in TheClass.TheProperty is a property of TheClass.

But I hope you get an idea of what we're trying to do. I guess in a way
we're trying to merge the properties from TheClass and AnotherClass
together.

And in writing that I've just answered my own question. This is object
inheritence which VB really suffers from not implementing (yeah know it's in
VB.NET) and as VB doesn't do inheritence, what I'm trying to do here won't
work.

Quote:
> And note that using *any* object's "default" property is going to require
> you to change your code for VB.Net (if you plan on using it) because there
> will be *no* default properties of any kind..

VB.Net is the least of our worries at the moment. We've not bought into the
Microsoft vision just yet...

Rob.



Mon, 24 Nov 2003 17:57:41 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. question about default property/having problems with For Each loop

2. default property not displayed in properties window.

3. .property vs. object.property question

4. Class Module Default Property

5. Default/Input mask property

6. default property for a contact item?

7. Change Default Account or Change Sender Properties - HELP !

8. Default property for a contactitem

9. Dynamic Connector default properties

10. How to set Default Property Value in subclass?

11. Changing default properties of controls

12. Create custom control change property default

 

 
Powered by phpBB® Forum Software