From: Richard B. <rb...@ar...> - 2003-09-24 22:35:53
|
I've fixed an issue with the AtomsFramework cache. If an object was retrieved in multiple forms in an MDI application and the object was changed in one form, then all the other objects across the application were also changed. This was because a reference to the cached object was being passed around, not fresh copies of the object. Effectively, there was only ever one copy of an object in an application. This is now fixed. When an object is saved a copy of it is placed in the cache. When an object is retrieved from the cache a copy is returned. The copies of the objects are made through the Copy method of the CPersistentObject class. By default, this method only performs a shallow copy of the object. References to other objects from within the class are copied, not the sub-objects themselves. For example, an order line contains a product object. When the order line is copied, the reference to the product object is copied. There is no new copy of the product object made. Here's an example of what this could mean: dim OL1, OL2 as COrderLine OL1 = new COrderLine OL1.OrderNumber = 1 OL1.retrieve(OL1) Console.WriteLine OL1.Product.Description ' Outputs:"Product ABCD" OL2 = OL1.Copy Console.WriteLine OL2.Product.Description ' Outputs: "Product ABCD" OL1.Product.Description = "XXX" Console.WriteLine OL1.Product.Description ' Outputs:"XXX" Console.WriteLine OL2.Product.Description ' Outputs: "XXX" - not "Product ABCD" This is find under normal circumstances. If you want to do a "deep copy" you need to override the copy method in your class as follows: Public Overrides Function Copy() As AToMSFramework.CPersistentObject Dim ol as COrderLine ol = MyBase.Copy ol.Product = me.Product.Copy return ol End Function If you do this then the example code above would be Console.WriteLine OL1.Product.Description ' Outputs:"XXX" Console.WriteLine OL2.Product.Description ' Outputs: "Product ABCD" Grab the latest version from source safe at your leisure. - Richard Banks http://www.arel.com http://www.arelretail.com |