Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > Instantiate class within a class

Reply
Thread Tools

Instantiate class within a class

 
 
Colin Mc Mahon
Guest
Posts: n/a
 
      08-12-2004
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


 
Reply With Quote
 
 
 
 
Tarwn
Guest
Posts: n/a
 
      08-13-2004
> 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
 
Reply With Quote
 
 
 
 
Colin Mc Mahon
Guest
Posts: n/a
 
      08-13-2004
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
"Tarwn" <> wrote in message
news:15962655-38D4-4CB7-98E1-...
> > 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



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to instantiate HttpRequest Object in class level pradeepsarathy@gmail.com Java 3 03-10-2006 12:04 PM
How to decide at runtime which concrete class implementation to instantiate java-john Java 7 03-08-2006 03:46 AM
Ways to instantiate a Class Lian Liming Java 13 11-03-2005 07:16 AM
instantiate an array of class Anthony C++ 6 06-02-2005 05:24 AM
dynamically instantiate a class Sumit Nagpal C++ 11 10-21-2004 05:41 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57