I am still evaluating EntityDAC,
I would like to be able to add an event when a model property changes. In this post, I am using standard delphi events (references to procedures). But in my application, I will use Spring4d multicast events.
So, I followed the instructions on the manual :
I managed to change the BaseClass of my entities and define another
Code: Select all
TMyEntity = class(TMappedEntity)
Then, in this TMyEntity, I have an event :
Code: Select all
fOnPropertyChanged : TPropertyChangedEvent;
Code: Select all
procedure NotifyAttributeChanged(const attributeName : string)
Code: Select all
NotifyAttributeChanged('<#= prop.Name #>');
Ex :
Code: Select all
aModel.Name := 'ANewName' // triggers the event
aDataSet.fieldByName('aFieldName').Value.AsSring := 'AnotherName'; // does not trigger the event
Being able to use the custom getters and setters both when updating data through the EntityDataSet AND the Entity itself would be great since it would allow some business rules to be validated regardless of the input "method" (DataSet fields or TEntity property setters).
Also, in this case, it would allow to add custom events that would be fired regardless of "How" the model is updated.
If in a form I have some DB aware controls bound to an EntityDataSet with SourceEntity := aEntity. I would also have a button that is enabled only if aEntity.IsBig = true. It would be way easier to simply bind myself to aEntity.OnPropertyChanged event rather than having to both check for the EntityDataSet and Entity changes.
Another example. If I have a UserRights Entity that is accessible through a Service. I could simply bind myself to the UserRights.OnPropertyChanged anywhere in my application. I could then update the ui to deactivate some actions or whatnot.
The reason I am using a dataset is because I have some data aware controls that are not LiveBinding-enabled (DevExpress). We are refactoring our code towards a more OO architecture, thus our interest in evaluating EntityDac.