#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2002
    Posts
    123
    Rep Power
    13

    object reference


    Hi,
    I have an object in a collection.
    I pass it by ref to a form in order to edit it (the form has a local var to hold it).
    I also store in the form an un-referenced copy of the object to allow the user canceling the operation (in which case I thought to 'return' the copied un-changed object).
    The problem is that when canceling, setting the local referencing variable to the copied unchanged object doesn't affect the original item in the collection - reference issue.
    Can I change the reference using AddressOf or ObjPtr (or anything else) so that setting the local referencing variable will do the trick?

    thanx
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2001
    Location
    Dublin
    Posts
    413
    Rep Power
    14
    can't you make the changes to the copy of the object - and just apply these (ie copy them to the collection-held / referenced object) once the form has been ok'd.
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2002
    Posts
    123
    Rep Power
    13
    That's what I do at the moment, but with objects that have many members it's a lengthy process. I'm looking for a more elegant solution to do the same thing.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2002
    Location
    Bavaria, Germany
    Posts
    140
    Rep Power
    12
    What you want is transaction based objects like they're used in MTS components (just like SQL transactions). But i guess that's a overkill ;-))

    Normally you apply changes to your object when you click 'OK' or 'Save', any change before is kept in another structure like a String or a Textarea. When the user clicks on OK, the String is set at your object.

    If you want to work with your object, then implementing Clone methods could also do the job. When you load your editing form, clone your object and let the form do instant manipulating of your clone. If the user clicks on 'OK', save the clone in your collection at the index of your original object.
  8. #5
  9. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2002
    Posts
    123
    Rep Power
    13
    the un-referenced object I mentioned is a clone of the one stored in the collection - there are 2 identical objects in the begining and the changes are done to one of them, but in order to discard the changes it is not enough to do 'Set ChangedObject = ClonedOriginalObject' cause the changes already took place (it's a reference) and the assignment won't undo them.
    What I need to do is set the actual place in memory pointing to the changed object so that it would point to the cloned unchanged one.

    I think it can be done using CopyMemory but I'm still checking it.

IMN logo majestic logo threadwatch logo seochat tools logo