Instantiate class within a class

C

Colin Mc Mahon

Hi all,

I currently use a class to interface with my databases, allowing me to
insert, update, delete and retrieve records from the database as methods of
the class.

I have now created a recordset class and want to in some way instantiate
this class via the database class i.e.

Set objDbase = New cDatabase
With objDbase
.Database = "/db/db.mdb"
.Connect
End With

........ other code ........

Set rsObj = New objDbase.Recordset
......... RS Manipulation methods in the cRecordset class

Set objDbase = Nothing


I have experimented with 'Property Set' Within the cDatabase class but to no
avail, as follows

Public Property Set Recordset (cRecordset)
Set i_rs = New cRecordset
End Property
Public Property Get Recordset ()
Set Recordset = i_rs
End Property

I confess to being a novice with 'Property Set' having never used it before,
and I can't seem to find any practical examples of it online. I know JScript
supports inheritance to a degree, but need to work with vbscript at the
moment.

BTW the idea behind all this is to be able to instantiate independant
pseudo-recordsets so they can be paginated/manipulated independantly. This
could not be done efficiently using the dbase class alone when it's instance
existed from beginning to end of a page, or another class. The reason I want
to do it as a property is so that each one can be individually referenced
instead of using a fixed internal variable in the dbase class for each rs
class, which would defeat the purpose of the rs class.

Hopefully that makes sense to someone out there! Any insight, information,
drection or advice on instantiating classes like this within a class in
classic asp/vbscript would be gratefully appreciated, even if it's to say
'that's not the way to go about it'!

Thanks in advance,
Colin
 
T

Tarwn

Public Property Set Recordset (cRecordset)
Set i_rs = New cRecordset
End Property

You maybe confusing things here. You have declared that the property expects
you to assign it an object that you will call cRecordset, but then inside the
property you try to instantiate a cRecordset object. I'm not entirely sure
what is going to happen, but I can tell this isn't what you were trying to
achieve.

If you are trying to pass an existing recordset to the object you might ant
to go with something like:

Public Property Set Recordset(aRecSet)
Set i_rs = aRecSet
End Property

this will assign the incoming assigned recordset to your internal recordset
variable.

If your trying to have the objDbase object instantiate and return a new
Recordset object you may want to createa seperate function or property to do
so. Something like:
Function GetNewRecordset()
Set GetNewRecordset = New cRecordset
End Function


You would not needto use the new keyword in your calling code, that is
handled here internally, so basically your code would look like:

Set rsObj = objDBase.GetNewRecordset()

Hope this was what you were looking for,

-T
 
C

Colin Mc Mahon

Thanks Tarwin,

Your exactly right of course, did that and it worked a treat. Now all I have
to do is to figure out how to paginate a 2 dimensional array :)

Each solution creates a new set of problems :)

Thanks for your reply
Colin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top