Instantiate class within a class

Discussion in 'ASP General' started by Colin Mc Mahon, Aug 12, 2004.

  1. 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
    Colin Mc Mahon, Aug 12, 2004
    #1
    1. Advertising

  2. Colin Mc Mahon

    Tarwn Guest

    > 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
    Tarwn, Aug 13, 2004
    #2
    1. Advertising

  3. 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:...
    > > 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
    Colin Mc Mahon, Aug 14, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lian Liming

    Ways to instantiate a Class

    Lian Liming, Nov 1, 2005, in forum: Java
    Replies:
    13
    Views:
    9,098
    Roedy Green
    Nov 3, 2005
  2. java-john
    Replies:
    7
    Views:
    930
    java-john
    Mar 8, 2006
  3. Replies:
    3
    Views:
    12,462
    Alex Hunsley
    Mar 10, 2006
  4. Sumit Nagpal

    dynamically instantiate a class

    Sumit Nagpal, Oct 20, 2004, in forum: C++
    Replies:
    11
    Views:
    809
    Sumit Nagpal
    Oct 21, 2004
  5. Anthony

    instantiate an array of class

    Anthony, Jun 1, 2005, in forum: C++
    Replies:
    6
    Views:
    4,750
    Farhan
    Jun 2, 2005
Loading...

Share This Page