Implementing listener and callback, infinite loop
Show older comments
Hi,
My problem follows the one I described here:
So in my example, a class "Car" as properties "Brand" and "Color".
Brand can only be 'Ferrari' or 'Mercedes', and 'Color' can only be Yellow or Red for the Ferrari and Black or Silver for the Mercedes.
I did put Color as Dependent and added a set method with a sort of pair property of color.
When set or get is called for Color, its a "twin" property that holds the value.
I have a list of valid Color input for the Ferrari and the Mercedes, so that when setting the Color of the car it as to be right.
It works fine, but if I change the Brand, then the Color is invalid but there is no check for that.
So I would like the Color Prop to change to the first Valid one (in the list) whenever "Brand" is modified.
For that I tried to implement a property that listen to the Brand property. ==>"BrandChangeListener"
I made the Car class to inherit form handle. Then I was getting a warning with my set methods, so I modified them from: obj = set.propName(obj, value) to set.propName(obj, value), so that it does not return the object anymore. That fixed the warning.
In the constructor I tried to implement a listener:
myCar.BrandChangeListener = event.proplistener(myCar, findprop(myCar, 'brand'),'PostSet', @ResetColor);
On this line I get the error: While adding a PostSet listener, property 'brand' in class 'car' is not defined to be SetObservable.
1 Comment
Stephen23
on 4 Dec 2017
@Laurent Davenne: this is not twitter. I removed the useless # characters from your tags.
Accepted Answer
More Answers (0)
Categories
Find more on Interactive Control and Callbacks in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!