Implementing listener and callback, infinite loop
显示 更早的评论
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 个评论
Stephen23
2017-12-4
@Laurent Davenne: this is not twitter. I removed the useless # characters from your tags.
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Interactive Control and Callbacks 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!