Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question about default properties

Status
Not open for further replies.

Informed

Technical User
Aug 11, 2000
3
GB
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top