Results 1 to 3 of 3

Thread: How to pass an object? And pass the real thing not only a pointer.

  1. #1
    Helger
    Guest

    How to pass an object? And pass the real thing not only a pointer.

    I'd like to fill up an object array with recordsets. Let's say I have

    dim aobjArr(1) as object
    dim rst as recordset

    rst.activeconnection = myConn
    rst.source = "SELECT * FROM tblA;"
    rst.open

    set aobjArr(0) = rst

    set datagrid1(0).datasource = aobjArr(0) 'works fine so far

    rst.close

    rst.source = "SELECT * FROM tblB;"
    rst.open

    set aobjArr(1) = rst

    set datagrid1(0).datasource = aobjArr(0)
    set datagrid1(1).datasource = aobjArr(1) 'the two datagrids will be filled with identical data from the second query.

    How can I overcome this? How can I pass the real thing and not just a reference? Is it possible to make one object BECOME another one and have all it's properties and when the one object changes the other won't?

    Like when I do

    set rstA = rstB

    as soon as I change rstA, rstB will change too. I don't want that. What do I have to do?

    thx,

    Helger

  2. #2
    jim mcnamara
    Guest
    Code:
    ' one way ---------
    
    dim aobjArr(1) as object 
    dim rst(1) as recordset 
    
    rst(0).activeconnection = myConn 
    rst(0).source = "SELECT * FROM tblA;" 
    rst(0).open 
    
    set aobjArr(0) = rst(0)
    
    set datagrid1(0).datasource = aobjArr(0) 'works fine so far 
    
    rst(0).close 
    <<<<<<<<<<<<<<
    rst(1).activeconnection = myConn 
    rst(1).source = "SELECT * FROM tblB;" 
    rst(1).open 
    
    
    rst(1).open 
    
    set aobjArr(1) = rst(1)
    It's too late in the day for me explain why, but with what you were doing you had the recordsets pointing to the same thing, so when you updated the rst (as what you thought was new, you were aslso updating what you thought was old and static. You were using an object pointer - when you change the object in instance B, it also changes instance A - because they point to the same thing.

    By the way Dim A as Object creates and object pointer, not an object.

    You could also have done Set rst = New Recordset, where the <<< is and not played the array game, if you don't like object arrays.

  3. #3
    Helger
    Guest
    Thanks I'll try tomorrow. Need to get some sleep first.

    Helger

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width