I am trying to use the Model-View-Controller pattern in a small application. The model contains some data and a selection like this
TModelSelection = record
CurrentItem : TItem;
end;
TModel = class
public
property Items : TList <TItem>;
property Selection : TModelSelection;
property Subject : TSubject <TModel>; // Observer pattern
end;
Now I have a tree view that observes the model. If the user selects an item in the tree view, the model selection should change.
The problem is that I run into problems with circular change notifications: I change the model selection in the tree view's OnChange event. This causes the tree view to update its selection (since the selection can also be changed by other parts of the application), which again triggers the OnChange event and so on.
How can I avoid this problem?