April 3rd, 2003, 03:42 AM
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?
April 3rd, 2003, 03:06 PM
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.
April 5th, 2003, 11:34 PM
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.
April 8th, 2003, 05:06 AM
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.
April 9th, 2003, 12:43 AM
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.