Is there a simple way to detect if an object and it's associated objects have changed. What I mean is how can I tell if Manager.Flush has pending changes to apply to the database. It would be really handy if there was a Manager.IsChanged boolean function that would work like the flush procedure with an overload to pass a single object.
I was looking at the mapping explorer and see there is a function ObjectChanged(OriginalObj, DirtyObj: TObject): Boolean; I wondered if I could use this and if so would the two objects have to have the same manager? I noticed you discussed this in a previous post and you stated that the parameter order was important but i didn't really get why. Isn't it just a comparison between two objects and there associations?
What is the exact purpose for that?
There is no such feature yet because to tell if an object is changed is complex conceptually: does it concern only to scalar properties? What if a property of an associated object is also changed? Does that mean parent object is considered changed - a Flush(Parent) will fire updates in database in this case. What about collections? Should it check for added/removed items?
You can use ObjectChanged if it fits your needs - although that's not exactly the function the manager uses. The reason why the order is important is because of proxies: an unloaded proxy means that property is untouched. So if the "DirtyObj" has an unloaded proxy it means it's not changed, regardless of what OriginalObj contains.
I want to disable a button on a form if it has unsaved work. That's the purpose for it. Thanks again for your help and your clear explanation of the 'ObjectChanged' function.
Many thanks Wagner for the new feature 'TObjectManager.HasChanges' in version 4.1. Released without fanfare but certainly arrived on my desktop with a tada . Just outstanding support :)
Hi Steve, you're welcome.
Thanks for the kind words, that feedback certainly is fuel for us to keep it going!